-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set up ethers and viem directories * Refactor the rest of the precompiles * Clean up comments * Add changeset * Fix jest test failing bc no tests * Remove ethers type for now
- Loading branch information
Showing
47 changed files
with
625 additions
and
1,996 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sei-js/evm': minor | ||
--- | ||
|
||
Refactored EVM package so that viem and ethers are now peer dependencies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,60 @@ | ||
{ | ||
"name": "@sei-js/evm", | ||
"version": "1.2.0", | ||
"description": "TypeScript library for EVM interactions on the Sei blockchain", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"types": "./dist/types/index.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"build": "yarn build:types && yarn build:cjs && yarn build:esm && yarn build:prettier", | ||
"build:cjs": "tsc --outDir dist/cjs --module commonjs", | ||
"build:esm": "tsc --outDir dist/esm --module esnext", | ||
"build:types": "tsc --project ./tsconfig.declaration.json", | ||
"build:prettier": "prettier --write 'dist/**/*.js'", | ||
"docs": "typedoc --out docs", | ||
"test": "jest", | ||
"lint": "eslint --ext .ts" | ||
}, | ||
"homepage": "https://github.com/sei-protocol/sei-js#readme", | ||
"keywords": [ | ||
"sei", | ||
"javascript", | ||
"typescript", | ||
"node", | ||
"evm" | ||
], | ||
"repository": "[email protected]:sei-protocol/sei-js.git", | ||
"license": "MIT", | ||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"ethers": "^6.0.0", | ||
"viem": "^2.0.0", | ||
"@wagmi/core": "^2.9.1" | ||
}, | ||
"peerDependencies": {}, | ||
"devDependencies": {}, | ||
"exports": { | ||
".": { | ||
"import": "./dist/esm/index.js", | ||
"require": "./dist/cjs/index.js", | ||
"types": "./dist/types/index.d.ts" | ||
} | ||
} | ||
"name": "@sei-js/evm", | ||
"version": "1.2.0", | ||
"description": "TypeScript library for EVM interactions on the Sei blockchain", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"types": "./dist/types/index.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"build": "yarn build:types && yarn build:cjs && yarn build:esm && yarn build:prettier", | ||
"build:cjs": "tsc --outDir dist/cjs --module commonjs", | ||
"build:esm": "tsc --outDir dist/esm --module esnext", | ||
"build:types": "tsc --project ./tsconfig.declaration.json", | ||
"build:prettier": "prettier --write 'dist/**/*.js'", | ||
"docs": "typedoc --out docs", | ||
"test": "jest --passWithNoTests", | ||
"lint": "eslint --ext .ts" | ||
}, | ||
"homepage": "https://github.com/sei-protocol/sei-js#readme", | ||
"keywords": [ | ||
"sei", | ||
"javascript", | ||
"typescript", | ||
"node", | ||
"evm" | ||
], | ||
"repository": "[email protected]:sei-protocol/sei-js.git", | ||
"license": "MIT", | ||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"ethers": "^6.0.0", | ||
"viem": "2.x" | ||
}, | ||
"devDependencies": { | ||
"ethers": "^6.0.0", | ||
"viem": "2.x" | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./dist/esm/index.js", | ||
"require": "./dist/cjs/index.js", | ||
"types": "./dist/types/index.d.ts" | ||
}, | ||
"./ethers": { | ||
"import": "./dist/esm/ethers/index.js", | ||
"require": "./dist/cjs/ethers/index.js", | ||
"types": "./dist/types/ethers/index.d.ts" | ||
}, | ||
"./viem": { | ||
"import": "./dist/esm/viem/index.js", | ||
"require": "./dist/cjs/viem/index.js", | ||
"types": "./dist/types/viem/index.d.ts" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ContractRunner, Contract, 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 | ||
*/ | ||
export const ETHERS_ADDRESS_PRECOMPILE_ABI = ADDRESS_PRECOMPILE_ABI as InterfaceAbi; | ||
|
||
/** | ||
* Creates and returns a typed Ethers v6 contract instance for the Address precompile contract. | ||
* This contract is used for interoperability between the EVM and Cosmos. | ||
* | ||
* @example | ||
* ```tsx | ||
* import { getAddressPrecompileEthersV6Contract } from '@sei-js/evm/ethers'; | ||
* import { ethers } from 'ethers'; | ||
* | ||
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider | ||
* const signer = await provider.getSigner(); | ||
* | ||
* const accounts = await provider.send('eth_requestAccounts', []); | ||
* | ||
* const addressPrecompileContract = getAddressPrecompileEthersV6Contract(signer); | ||
* | ||
* const seiAddr = await addressPrecompileContract.getSeiAddr(accounts[0]); | ||
* ``` | ||
* | ||
* @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 | ||
*/ | ||
export function getAddressPrecompileEthersV6Contract(runner: ContractRunner) { | ||
return new Contract(ADDRESS_PRECOMPILE_ADDRESS, ETHERS_ADDRESS_PRECOMPILE_ABI, runner); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Contract, ContractRunner, 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 | ||
*/ | ||
export const ETHERS_BANK_PRECOMPILE_ABI = BANK_PRECOMPILE_ABI as InterfaceAbi; | ||
|
||
/** | ||
* Creates and returns a typed Ethers v6 contract instance for the Bank precompile contract. | ||
* This contract is used for interoperability between the EVM and Cosmos. | ||
* | ||
* @example | ||
* ```tsx | ||
* import { getBankPrecompileEthersV6Contract } from '@sei-js/evm/ethers'; | ||
* import { ethers } from 'ethers'; | ||
* | ||
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider | ||
* const signer = await provider.getSigner(); | ||
* | ||
* const accounts = await provider.send('eth_requestAccounts', []); | ||
* | ||
* const bankPrecompileContract = getBankPrecompileEthersV6Contract(signer); | ||
* | ||
* const balance = await bankPrecompileContract.balance(accounts[0], 'usei'); | ||
* console.log('Balance:', balance); | ||
* ``` | ||
* | ||
* @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 | ||
*/ | ||
export const getBankPrecompileEthersV6Contract = (runner: ContractRunner) => { | ||
return new Contract(BANK_PRECOMPILE_ADDRESS, BANK_PRECOMPILE_ABI, runner); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Contract, ContractRunner, 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 | ||
*/ | ||
export const ETHERS_DISTRIBUTION_PRECOMPILE_ABI = DISTRIBUTION_PRECOMPILE_ABI as InterfaceAbi; | ||
|
||
/** | ||
* Creates and returns a typed Ethers v6 contract instance for the Distribution precompile contract. | ||
* This contract is used for interoperability between the EVM and Cosmos. | ||
* | ||
* @example | ||
* ```tsx | ||
* import { getDistributionPrecompileEthersV6Contract } from '@sei-js/evm/ethers'; | ||
* import { ethers } from 'ethers'; | ||
* | ||
* const provider = new ethers.BrowserProvider(); // or any other provider | ||
* const signer = provider.getSigner(); | ||
* | ||
* const contract = getDistributionPrecompileEthersV6Contract(signer); | ||
* | ||
* const response = await contract.setWithdrawAddress('0xADDRESS'); | ||
* console.log('Response:', response); | ||
* ``` | ||
* | ||
* @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 | ||
*/ | ||
export const getDistributionPrecompileEthersV6Contract = (runner: ContractRunner) => { | ||
return new Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, ETHERS_DISTRIBUTION_PRECOMPILE_ABI, runner); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Contract, ContractRunner, 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 | ||
*/ | ||
export const ETHERS_GOVERNANCE_PRECOMPILE_ABI = GOVERNANCE_PRECOMPILE_ABI as InterfaceAbi; | ||
|
||
/** | ||
* Creates and returns a typed Ethers v6 contract instance for the Governance precompile contract. | ||
* This contract is used for interoperability between the EVM and Cosmos. | ||
* | ||
* @example | ||
* ```tsx | ||
* import { getGovernancePrecompileEthersV6Contract, parseSei } from '@sei-js/evm/ethers'; | ||
* import { ethers } 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) }); | ||
* 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 | ||
*/ | ||
export const getGovernancePrecompileEthersV6Contract = (runner: ContractRunner) => { | ||
return new Contract(GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, runner); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Contract, ContractRunner, InterfaceAbi } from 'ethers'; | ||
import { IBC_PRECOMPILE_ABI, IBC_PRECOMPILE_ADDRESS } from '../precompiles'; | ||
|
||
/** | ||
* The ABI for the IBC precompile contract, used to create an Ethers contract. | ||
* @category Cosmos Interoperability | ||
*/ | ||
export const ETHERS_IBC_PRECOMPILE_ABI = IBC_PRECOMPILE_ABI as InterfaceAbi; | ||
|
||
/** | ||
* Creates and returns a typed Ethers v6 contract instance for the IBC precompile contract. | ||
* This contract is used for interoperability between the EVM and Cosmos. | ||
* | ||
* @example | ||
* ```tsx | ||
* import { getIbcPrecompileEthersV6Contract } from '@sei-js/evm/ethers'; | ||
* import { ethers } from 'ethers'; | ||
* | ||
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider | ||
* const signer = await provider.getSigner(); | ||
* | ||
* const ibcPrecompileContract = getIbcPrecompileEthersV6Contract(signer); | ||
* const cosmosAddress = 'cosmos1...'; | ||
* | ||
* const bool = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo'); | ||
* console.log('Transfer successful:', bool); | ||
* ``` | ||
* | ||
* @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 IBC precompile contract. | ||
* @category Cosmos Interoperability | ||
*/ | ||
export const getIbcPrecompileEthersV6Contract = (runner: ContractRunner) => { | ||
return new Contract(IBC_PRECOMPILE_ADDRESS, ETHERS_IBC_PRECOMPILE_ABI, runner); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export * from './addressPrecompile'; | ||
export * from './bankPrecompile'; | ||
export * from './distributionPrecompile'; | ||
export * from './governancePrecompile'; | ||
export * from './ibcPrecompile'; | ||
export * from './jsonPrecompile'; | ||
export * from './oraclePrecompile'; | ||
export * from './pointerPrecompile'; | ||
export * from './pointerviewPrecompile'; | ||
export * from './stakingPrecompile'; | ||
export * from './wasmPrecompile'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Contract, ContractRunner, InterfaceAbi } from 'ethers'; | ||
import { JSON_PRECOMPILE_ABI, JSON_PRECOMPILE_ADDRESS } from '../precompiles'; | ||
|
||
/** | ||
* The ABI for the JSON precompile contract, used to create an Ethers contract. | ||
* @category Cosmos Interoperability | ||
*/ | ||
export const ETHERS_JSON_PRECOMPILE_ABI = JSON_PRECOMPILE_ABI as InterfaceAbi; | ||
|
||
/** | ||
* Creates and returns a typed Ethers v6 contract instance for the JSON precompile contract. | ||
* This contract is used for interoperability between the EVM and Cosmos. | ||
* | ||
* @example | ||
* ```tsx | ||
* import { getJSONPrecompileEthersV6Contract } from '@sei-js/evm/ethers'; | ||
* import { ethers } from 'ethers'; | ||
* | ||
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider | ||
* const signer = await provider.getSigner(); | ||
* | ||
* const accounts = await provider.send('eth_requestAccounts', []); | ||
* | ||
* const jsonPrecompileContract = getJSONPrecompileEthersV6Contract(signer); | ||
* | ||
* const response = await jsonPrecompileContract.extractAsBytes('0xINPUT', 'KEY'); | ||
* console.log('Response:', response); | ||
* ``` | ||
* | ||
* @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 JSON precompile contract. | ||
* @category Cosmos Interoperability | ||
*/ | ||
export const getJSONPrecompileEthersV6Contract = (runner: ContractRunner) => { | ||
return new Contract(JSON_PRECOMPILE_ADDRESS, ETHERS_JSON_PRECOMPILE_ABI, runner); | ||
}; |
Oops, something went wrong.