-
Notifications
You must be signed in to change notification settings - Fork 29
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
integrations/viem: initial package work #268
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,23 +1,23 @@ | ||
{ | ||
"name": "example-ethersv5-ts-esm", | ||
"private": true, | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"lint": "prettier --cache --plugin-search-dir=. --check *.cjs test/**.ts scripts/**.ts contracts/**.sol && solhint contracts/**.sol", | ||
"format": "prettier --cache --plugin-search-dir=. --write *.cjs test/**.ts scripts/**.ts contracts/**.sol && solhint --fix contracts/**.sol", | ||
"build": "tsc -b", | ||
"test": "tsc -b && pnpm node build/examples/ethersv5-ts-esm/src/index.js" | ||
}, | ||
"dependencies": { | ||
"@oasisprotocol/sapphire-paratime": "workspace:^", | ||
"ethers": "5.5.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.10", | ||
"@tsconfig/strictest": "2.0.2", | ||
"prettier": "^2.5.1", | ||
"ts-node": "10.9.2", | ||
"typescript": "4.7.4" | ||
} | ||
"name": "example-ethersv5-ts-esm", | ||
"private": true, | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"lint": "prettier --cache --plugin-search-dir=. --check *.cjs test/**.ts scripts/**.ts contracts/**.sol && solhint contracts/**.sol", | ||
"format": "prettier --cache --plugin-search-dir=. --write *.cjs test/**.ts scripts/**.ts contracts/**.sol && solhint --fix contracts/**.sol", | ||
"build": "tsc -b", | ||
"test": "tsc -b && pnpm node build/examples/ethersv5-ts-esm/src/index.js" | ||
}, | ||
"dependencies": { | ||
"@oasisprotocol/sapphire-paratime": "workspace:^", | ||
"ethers": "5.5.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.10", | ||
"@tsconfig/strictest": "2.0.2", | ||
"prettier": "^2.5.1", | ||
"ts-node": "10.9.2", | ||
"typescript": "4.7.4" | ||
} | ||
} |
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,20 +1,20 @@ | ||
{ | ||
"name": "example-ethersv6-ts-esm", | ||
"private": true, | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc -b", | ||
"test": "tsc -b && pnpm node build/examples/ethersv6-ts-esm/src/index.js" | ||
}, | ||
"dependencies": { | ||
"@oasisprotocol/sapphire-paratime": "workspace:^", | ||
"ethers": "6.9.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.10", | ||
"@tsconfig/strictest": "2.0.2", | ||
"ts-node": "10.9.2", | ||
"typescript": "5.3.3" | ||
} | ||
"name": "example-ethersv6-ts-esm", | ||
"private": true, | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc -b", | ||
"test": "tsc -b && pnpm node build/examples/ethersv6-ts-esm/src/index.js" | ||
}, | ||
"dependencies": { | ||
"@oasisprotocol/sapphire-paratime": "workspace:^", | ||
"ethers": "6.9.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.10", | ||
"@tsconfig/strictest": "2.0.2", | ||
"ts-node": "10.9.2", | ||
"typescript": "5.3.3" | ||
} | ||
} |
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 @@ | ||
build |
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,21 @@ | ||
{ | ||
"name": "example-viem", | ||
"private": true, | ||
"type": "module", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "tsc -b", | ||
"test": "tsc -b && node --loader ts-node/esm src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@oasisprotocol/sapphire-viem": "workspace:^", | ||
"viem": "^2.7.1" | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/strictest": "2.0.2", | ||
"@types/node": "^17.0.10", | ||
"abitype": "^1.0.0", | ||
"ts-node": "10.9.2", | ||
"typescript": "5.3.3" | ||
} | ||
} |
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,41 @@ | ||
import { Hex, createWalletClient, getContract, http, publicActions } from 'viem'; | ||
|
||
import OmnibusJSON from "../../../contracts/artifacts/contracts/tests/Omnibus.sol/Omnibus.json" assert { type: "json" }; | ||
import { narrow } from 'abitype' | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
import { sapphireLocalnet, wrapWalletClient } from '@oasisprotocol/sapphire-viem'; | ||
|
||
|
||
async function main () { | ||
const account = privateKeyToAccount('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'); | ||
|
||
const transport = http('http://127.0.0.1:3000'); | ||
|
||
const walletClient = wrapWalletClient(createWalletClient({ | ||
account, | ||
chain: sapphireLocalnet, | ||
transport | ||
})); | ||
|
||
const hash = await walletClient.deployContract({ | ||
abi: narrow(OmnibusJSON.abi), | ||
bytecode: OmnibusJSON.bytecode as Hex, | ||
}); | ||
|
||
const pc = walletClient.extend(publicActions); | ||
const receipt = await pc.waitForTransactionReceipt({hash}); | ||
console.log('Receipt', receipt); | ||
|
||
const contractAddress = receipt.contractAddress!; | ||
|
||
console.log('getContract') | ||
const c = getContract({ | ||
address: contractAddress, | ||
abi: narrow(OmnibusJSON.abi), | ||
client: walletClient | ||
}) | ||
const x = await c.read['testSignedQueries']!(); | ||
console.log(x); | ||
} | ||
|
||
await main (); |
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,14 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "@tsconfig/strictest/tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./build", | ||
"module": "NodeNext", | ||
"target": "ES2022", | ||
"moduleResolution": "NodeNext", | ||
"resolveJsonModule": true | ||
}, | ||
"include": [ | ||
"./src" | ||
] | ||
} |
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,4 @@ | ||
node_modules | ||
dist | ||
*.tgz | ||
*.tsbuildinfo |
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,83 @@ | ||
{ | ||
"type": "module", | ||
"name": "@oasisprotocol/sapphire-viem", | ||
"license": "Apache-2.0", | ||
"version": "0.1.0", | ||
"description": "Viem support for the Oasis Sapphire ParaTime.", | ||
"homepage": "https://github.com/oasisprotocol/sapphire-paratime/tree/main/integrations/viem", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/oasisprotocol/sapphire-paratime.git" | ||
}, | ||
"keywords": [ | ||
"sapphire", | ||
"paratime", | ||
"oasis", | ||
"web3", | ||
"viem", | ||
"wagmi" | ||
], | ||
"files": [ | ||
"dist", | ||
"!dist/*.tsbuildinfo", | ||
"src" | ||
], | ||
"sideEffects": false, | ||
"main": "./dist/_cjs/index.js", | ||
"module": "./dist/_esm/index.js", | ||
"types": "./dist/_types/index.d.ts", | ||
"typings": "./dist/_types/index.d.ts", | ||
"exports": { | ||
"node": { | ||
"import": "./dist/_esm/index.js", | ||
"require": "./dist/_cjs/index.cjs", | ||
"types": "./dist/_types/index.d.ts" | ||
}, | ||
"default": "./dist/_esm/index.js" | ||
}, | ||
"scripts": { | ||
"lint": "prettier --cache --check . && eslint --ignore-path .gitignore .", | ||
"format": "prettier --cache --write . && eslint --ignore-path .gitignore --fix .", | ||
"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:types", | ||
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./dist/_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./dist/_cjs/package.json", | ||
"build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./dist/_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./dist/_esm/package.json", | ||
"build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./dist/_types --emitDeclarationOnly --declaration --declarationMap", | ||
"clean": "rm -rf dist", | ||
"test": "jest", | ||
"coverage": "jest --coverage", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"@noble/hashes": "1.3.2", | ||
"@oasisprotocol/deoxysii": "0.0.5", | ||
"tweetnacl": "1.0.3", | ||
"viem": "2.x", | ||
"cborg": "1.10.2", | ||
"type-fest": "2.19.0", | ||
"@oasisprotocol/sapphire-paratime": "workspace:^" | ||
}, | ||
"peerDependencies": { | ||
"viem": "2.x", | ||
"typescript": ">=5.0.4" | ||
}, | ||
"peerDependenciesMeta": { | ||
"typescript": { | ||
"optional": true | ||
} | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.11", | ||
"@types/node": "^18.7.18", | ||
"@types/node-fetch": "^2.6.2", | ||
"@typescript-eslint/eslint-plugin": "^5.38.0", | ||
"@typescript-eslint/parser": "^5.38.0", | ||
"eslint": "^8.23.1", | ||
"eslint-config-prettier": "^8.5.0", | ||
"jest": "^29.7.0", | ||
"node-fetch": "^2.6.7", | ||
"prettier": "^2.7.1", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
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,97 @@ | ||
import type { Chain } from "viem"; | ||
|
||
export const sapphireLocalnet = { | ||
id: 23293, | ||
name: "Oasis Sapphire Localnet", | ||
//network: "sapphire-localnet", | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: "Test Rose", | ||
symbol: "TEST", | ||
}, | ||
rpcUrls: { | ||
public: { | ||
http: ["http://localhost:8545"], | ||
webSocket: ["wss://localhost:8545/ws"], | ||
}, | ||
default: { | ||
http: ["https://localhost:8545"], | ||
webSocket: ["wss://localhost:8545/ws"], | ||
}, | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: "Oasis Foundation", | ||
url: "https://explorer.sapphire.oasis.io/", | ||
}, | ||
}, | ||
} as const satisfies Chain; | ||
|
||
export const sapphire = { | ||
id: 23294, | ||
name: "Oasis Sapphire", | ||
//network: "sapphire", | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: "Rose", | ||
symbol: "ROSE", | ||
}, | ||
rpcUrls: { | ||
public: { | ||
http: ["https://sapphire.oasis.io"], | ||
webSocket: ["wss://sapphire.oasis.io/ws"], | ||
}, | ||
default: { | ||
http: ["https://sapphire.oasis.io"], | ||
webSocket: ["wss://sapphire.oasis.io/ws"], | ||
}, | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: "Oasis Foundation", | ||
url: "https://explorer.sapphire.oasis.io/", | ||
}, | ||
}, | ||
} as const satisfies Chain; | ||
|
||
export const sapphireTestnet = { | ||
id: 23295, | ||
name: "Oasis Sapphire Testnet", | ||
//network: "sapphireTest", | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: "Rose", | ||
symbol: "ROSE", | ||
}, | ||
rpcUrls: { | ||
public: { | ||
http: ["https://testnet.sapphire.oasis.dev"], | ||
webSocket: ["wss://testnet.sapphire.oasis.dev/ws"], | ||
}, | ||
default: { | ||
http: ["https://testnet.sapphire.oasis.dev"], | ||
webSocket: ["wss://testnet.sapphire.oasis.dev/ws"], | ||
}, | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: "Oasis Foundation", | ||
url: "https://testnet.explorer.sapphire.oasis.dev/", | ||
}, | ||
}, | ||
} as const satisfies Chain; | ||
|
||
export const getSapphireChain = (chainId?: string): Chain => { | ||
if( chainId === undefined ) { | ||
return sapphire; | ||
} | ||
switch (chainId) { | ||
case "23294": | ||
return sapphire; | ||
case "23295": | ||
return sapphireTestnet; | ||
case "23293": | ||
return sapphireLocalnet; | ||
} | ||
throw new Error(`Unknown Sapphire chain id: ${chainId}`); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May not be using Viem right. I get a deploy error.