diff --git a/clients/js/.eslintrc.cjs b/clients/js/.eslintrc.cjs index 672e766f..e7236db3 100644 --- a/clients/js/.eslintrc.cjs +++ b/clients/js/.eslintrc.cjs @@ -20,5 +20,6 @@ module.exports = { rules: { '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-non-null-assertion': 'off', + eqeqeq: ['warn', 'always'], }, }; diff --git a/clients/js/CHANGELOG.md b/clients/js/CHANGELOG.md index 3fefb1ce..37497ec6 100644 --- a/clients/js/CHANGELOG.md +++ b/clients/js/CHANGELOG.md @@ -6,6 +6,23 @@ The format is inspired by [Keep a Changelog]. [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ +## 1.3.1 (2024-01-26) + +### Fixed + +- Ethers v6 signed queries +- Removed ethers & @noble/hashes from peer dependencies + +### Deprecated + +- Web3.js is not supported + +## 1.3.0 (2024-01-24) + +### Changed + +- Uses Ethers v6 behind the scenes + ## 1.2.0 (2023-11-15) ### Added diff --git a/clients/js/README.md b/clients/js/README.md index 3ee227ee..8693c025 100644 --- a/clients/js/README.md +++ b/clients/js/README.md @@ -1,14 +1,14 @@ # Sapphire ParaTime Compat Lib [@oasisprotocol/sapphire-paratime] makes it easy to port your dapp to the [Sapphire ParaTime] -by wrapping your existing `ethers.Provider`/`window.ethereum`/`web3.providers.*`. +by wrapping your existing `ethers.Provider`/`window.ethereum`. Once you wrap your provider, you can use Sapphire just like you would use Ethereum. [@oasisprotocol/sapphire-paratime]: https://www.npmjs.com/package/@oasisprotocol/sapphire-paratime [sapphire paratime]: https://docs.oasis.io/dapp/sapphire/ -_If your dapp doesn't port in under 10 minutes, it's a bug!_ -If you have more than a little trouble, please file an issue. +_If your dapp doesn't port in under 10 minutes, it's a bug!_
+If you have more than a little trouble, please file an issue.
There should be _no_ reason _not_ to use the Sapphire ParaTime! ## Usage @@ -50,15 +50,6 @@ const provider = sapphire.wrap( ); ``` -### web3.js - -```ts -import Web3 from 'web3'; -import * as sapphire from '@oasisprotocol/sapphire-paratime'; - -web3.setProvider(sapphire.wrap(web3.currentProvider)); -``` - ### [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) ```ts diff --git a/clients/js/package.json b/clients/js/package.json index 1dcd75cf..3f47ec8e 100644 --- a/clients/js/package.json +++ b/clients/js/package.json @@ -2,7 +2,7 @@ "type": "module", "name": "@oasisprotocol/sapphire-paratime", "license": "Apache-2.0", - "version": "1.3.0", + "version": "1.3.1", "description": "The Sapphire ParaTime Web3 integration library.", "homepage": "https://github.com/oasisprotocol/sapphire-paratime/tree/main/clients/js", "repository": { @@ -39,15 +39,16 @@ "build:cjs": "tsc -p ./tsconfig.cjs.json && node scripts/rename-cjs", "test": "jest", "coverage": "jest --coverage", - "prepublishOnly": "npm run build" + "prepublishOnly": "npm run build", + "proxy": "node --loader ts-node/esm scripts/proxy.ts" }, "dependencies": { "@oasisprotocol/deoxysii": "0.0.5", - "cborg": "^1.10.2", - "ethers": "^6.10.0", + "cborg": "1.10.2", + "ethers": "6.10.0", "@noble/hashes": "1.3.2", "tweetnacl": "1.0.3", - "type-fest": "^2.19.0" + "type-fest": "2.19.0" }, "devDependencies": { "@types/jest": "^29.5.11", @@ -65,9 +66,5 @@ "ts-node": "^10.9.2", "typedoc": "^0.25.4", "typescript": "^4.8.3" - }, - "peerDependencies": { - "ethers": "6.x", - "@noble/hashes": "1.x" } } diff --git a/clients/js/scripts/proxy.ts b/clients/js/scripts/proxy.ts index fe25634b..4982d71f 100644 --- a/clients/js/scripts/proxy.ts +++ b/clients/js/scripts/proxy.ts @@ -22,7 +22,17 @@ async function getBody(request: IncomingMessage): Promise { }); } -createServer(onRequest).listen(3000); +const LISTEN_PORT = 3000; +const DIE_ON_UNENCRYPTED = true; +const UPSTREAM_URL = 'http://127.0.0.1:8545'; +const SHOW_ENCRYPTED_RESULTS = true; + +console.log('DIE_ON_UNENCRYPTED', DIE_ON_UNENCRYPTED); +console.log('UPSTREAM_URL', UPSTREAM_URL); +console.log('LISTEN_PORT', LISTEN_PORT); +console.log('SHOW_ENCRYPTED_RESULTS', SHOW_ENCRYPTED_RESULTS); + +createServer(onRequest).listen(LISTEN_PORT); interface JSONRPCRequest { jsonrpc: string; @@ -32,7 +42,7 @@ interface JSONRPCRequest { } async function onRequest(req: IncomingMessage, response: ServerResponse) { - if (req.method != 'POST') { + if (req.method !== 'POST') { response.writeHead(500, 'Not POST!'); response.end(); return; @@ -53,16 +63,18 @@ async function onRequest(req: IncomingMessage, response: ServerResponse) { bodies = [inputBody]; } + let showResult = false; for (const body of bodies) { const log = loggedMethods.includes(body.method); if (log) { - if (body.method == 'oasis_callDataPublicKey') { + if (body.method === 'oasis_callDataPublicKey') { console.log(req.method, req.url, body.method); } else if ( - body.method == 'eth_estimateGas' || - body.method == 'eth_call' + body.method === 'eth_estimateGas' || + body.method === 'eth_call' ) { + let isSignedQuery = false; try { const x = getBytes(body.params[0].data); const y = cborg.decode(x); @@ -70,22 +82,49 @@ async function onRequest(req: IncomingMessage, response: ServerResponse) { if ('data' in y) { // EIP-712 signed queries are wrapped as follows: // {data: {body{pk:,data:,nonce:},format:},leash:{nonce:,block_hash:,block_range:,block_number:},signature:} - assert(y.data.format == 1); + assert(y.data.format === 1); + isSignedQuery = true; } else { - assert(y.format == 1); + assert(y.format === 1); } - console.log('ENCRYPTED', req.method, req.url, body.method); + console.log( + 'ENCRYPTED' + (isSignedQuery ? ' SIGNED QUERY' : ''), + req.method, + req.url, + body.method, + ); + showResult = true; } catch (e: any) { - console.log('NOT ENCRYPTED', req.method, req.url, body.method); + if (DIE_ON_UNENCRYPTED) { + console.log(e); + console.log(body); + throw new Error( + `NOT ENCRYPTED ${req.method} ${req.url} ${body.method}`, + ); + } + console.log( + 'NOT ENCRYPTED' + (isSignedQuery ? ' SIGNED QUERY' : ''), + req.method, + req.url, + body.method, + ); } - } else if (body.method == 'eth_sendRawTransaction') { + } else if (body.method === 'eth_sendRawTransaction') { try { const x = getBytes(body.params[0]); const y = decodeRlp(x) as string[]; //console.log(pj); const z = cborg.decode(getBytes(y[5])); - assert(z.format == 1); // Verify envelope format == 1 (encrypted) + assert(z.format === 1); // Verify envelope format == 1 (encrypted) console.log('ENCRYPTED', req.method, req.url, body.method); + showResult = true; } catch (e: any) { + if (DIE_ON_UNENCRYPTED) { + console.log(e); + console.log(body); + throw new Error( + `NOT ENCRYPTED ${req.method} ${req.url} ${body.method}`, + ); + } console.log( 'NOT ENCRYPTED', req.method, @@ -98,13 +137,16 @@ async function onRequest(req: IncomingMessage, response: ServerResponse) { } } - const pr = await fetch('http://127.0.0.1:8545/', { + const pr = await fetch(UPSTREAM_URL, { method: 'POST', body: JSON.stringify(inputBody), headers: { 'Content-Type': 'application/json' }, }); const pj = await pr.json(); + if (SHOW_ENCRYPTED_RESULTS && showResult) { + console.log(' - RESULT', pj); + } response.writeHead(200, 'OK'); response.write(JSON.stringify(pj)); diff --git a/clients/js/src/compat.ts b/clients/js/src/compat.ts index bf5c5a55..71da46a7 100644 --- a/clients/js/src/compat.ts +++ b/clients/js/src/compat.ts @@ -71,7 +71,6 @@ function fillOptions( * ethers.providers.Web3Provider(window.ethereum) * ethers.Wallet(privateKey) * ethers.getDefaultProvider(NETWORKS.testnet.defaultGateway) - * web3.currentProvider * window.ethereum * a Web3 gateway URL * ``` @@ -166,7 +165,9 @@ function hookEIP1193Request( const signer = await provider.getSigner(); const { method, params } = await prepareRequest(args, signer, options); const res = await signer.provider.send(method, params ?? []); - if (method === 'eth_call') return options.cipher.decryptEncoded(res); + if (method === 'eth_call') { + return options.cipher.decryptEncoded(res); + } return res; }; } @@ -294,8 +295,8 @@ function isEthers5Signer(upstream: object): upstream is Ethers5Signer { function isEthers6Signer(upstream: object): upstream is Signer { return ( upstream instanceof AbstractSigner || - (Reflect.get(upstream, 'signTypedData') && - Reflect.get(upstream, 'signTransaction')) + (Reflect.get(upstream, 'signTypedData') !== undefined && + Reflect.get(upstream, 'signTransaction') !== undefined) ); } @@ -308,7 +309,6 @@ function isEthers5Provider(upstream: object): upstream is Ethers5Signer { } function isEthers6Provider(upstream: object): upstream is Provider { - // return ( upstream instanceof AbstractProvider || (Reflect.get(upstream, 'waitForBlock') && @@ -339,12 +339,20 @@ function hookEthersCall( call.data ?? new Uint8Array(), ); } - return runner[method]!({ + const result = await runner[method]!({ ...call, data: hexlify(call_data!), }); + return result; }; return async (call) => { + // Ethers v6 uses `populateCall` internally to fill in the `from` field etc. + // It's necessary to call this, if it exists, otherwise signed queries won't work + const populateCall = Reflect.get(runner, 'populateCall'); + if (populateCall !== undefined) { + call = await populateCall.bind(runner)(call); + } + let res: string; const is_already_enveloped = isCalldataEnveloped(call.data!, true); if (!is_already_enveloped && isEthersSigner(runner)) { @@ -366,7 +374,7 @@ function hookEthersCall( } // NOTE: if it's already enveloped, caller will decrypt it (not us) if (!is_already_enveloped && typeof res === 'string') { - return options.cipher.decryptEncoded(res); + return await options.cipher.decryptEncoded(res); } return res; }; @@ -376,7 +384,9 @@ type EthersCall = (tx: EthCall | TransactionRequest) => Promise; function hookEthersSend(send: C, options: SapphireWrapOptions): C { return (async (tx: EthCall | TransactionRequest, ...rest: any[]) => { - if (tx.data) tx.data = await options.cipher.encryptEncode(tx.data); + if (tx.data) { + tx.data = await options.cipher.encryptEncode(tx.data); + } return (send as any)(tx, ...rest); }) as C; } @@ -452,7 +462,7 @@ async function repackRawTx( // When transaction is signed by another keypair and we don't have that signer // bypass re-packing, this allows repacking to pass-thru pre-signed txs - if (tx.isSigned() && (!signer || (await signer!.getAddress()) != tx.from!)) { + if (tx.isSigned() && (!signer || (await signer!.getAddress()) !== tx.from!)) { return raw; } @@ -516,7 +526,7 @@ function envelopeFormatOk(envelope: Envelope): boolean { if (!body) return false; - if (format != null && format !== CipherKind.Plain) { + if (format !== null && format !== CipherKind.Plain) { if (isBytesLike(body)) return false; if (!isBytesLike(body.data)) return false; @@ -611,7 +621,7 @@ export async function fetchRuntimePublicKeyByChainId( } function fromQuantity(x: number | string): number { - if (typeof x == 'string') { + if (typeof x === 'string') { if (x.startsWith('0x')) { return parseInt(x, 16); } diff --git a/clients/js/test/compat.spec.ts b/clients/js/test/compat.spec.ts index d01a891d..cb8fad21 100644 --- a/clients/js/test/compat.spec.ts +++ b/clients/js/test/compat.spec.ts @@ -107,27 +107,6 @@ class MockEIP1193Provider { } } -/* -class MockLegacyProvider extends MockEIP1193Provider { - public readonly isMetaMask = true; - public readonly sendAsync: ( - args: { id?: string | number; method: string; params?: any[] }, - cb: (err: unknown, ok?: unknown) => void, - ) => void; - - public constructor() { - super(); - this.sendAsync = (args, cb) => { - this.request(args) - .then((res: any) => { - cb(null, { jsonrpc: '2.0', id: args.id, result: res }); - }) - .catch((err) => cb(err)); - }; - } -} -*/ - class MockNonRuntimePublicKeyProvider { public readonly request: jest.Mock< Promise, @@ -144,7 +123,7 @@ class MockNonRuntimePublicKeyProvider { this.request = jest.fn((args) => { // Always errors while requesting the calldata public key // This simulates, e.g. MetaMask, which doesn't allow arbitrary requests - if (args.method == 'oasis_callDataPublicKey') { + if (args.method === 'oasis_callDataPublicKey') { throw new Error(`unhandled web3 call`); } return new MockEIP1193Provider().request(args); @@ -157,15 +136,6 @@ describe('fetchRuntimePublicKey', () => { jest.clearAllMocks(); }); - /* - it('legacy metamask provider', async () => { - const upstream = new ethers.BrowserProvider(new MockLegacyProvider()); - const pk = await fetchRuntimePublicKey(upstream); - expect(fetchRuntimePublicKeyByChainId).not.toHaveBeenCalled(); - expect(pk).toEqual(new Uint8Array(Buffer.alloc(32, 42))); - }); - */ - it('ethers provider', async () => { const upstream = new ethers.BrowserProvider(new MockEIP1193Provider()); const pk = await fetchRuntimePublicKey(upstream); @@ -214,10 +184,21 @@ describe('ethers signer', () => { const response = await wrapped.call(callRequest); expect(response).toEqual('0x112358'); - const encryptedCall = upstreamProvider.request.mock.calls[1][0].params![0]; - expect(encryptedCall.data).toEqual( - await cipher.encryptEncode(callRequest.data), + + const y = upstreamProvider.request.mock.calls.find( + (z) => z[0].method === 'eth_call', + )![0]; + + // This will be a signed view call, so it will be enveloped + // Make sure that the view call is enveloped, and can be decrypted + const decryptedBody = cbor.decode(ethers.getBytes(y.params![0].data)); + expect(decryptedBody.leash).toBeDefined(); + expect(decryptedBody.signature).toBeDefined(); + const decryptedInnerBody = await cipher.decryptCallData( + decryptedBody.data.body.nonce, + decryptedBody.data.body.data, ); + expect(ethers.hexlify(decryptedInnerBody)).toEqual(callRequest.data); const gasUsed = await wrapped.estimateGas(callRequest); expect(gasUsed).toEqual(BigInt(0x112358)); @@ -294,40 +275,6 @@ describe('window.ethereum', () => { }); }); -/* -describe('legacy MetaMask', () => { - it('proxy', async () => { - const wrapped = wrap(new MockLegacyProvider(), { cipher }); - expect(wrapped.isMetaMask).toBe(true); - expect(wrapped.isConnected()).toBe(false); - expect((wrapped as any).sapphire).toMatchObject({ cipher }); - }); - - runTestBattery(async () => { - const provider = new MockLegacyProvider(); - const wrapped = wrap(provider, { cipher }); - const signer = await new ethers.BrowserProvider(wrapped).getSigner(); - const rawSign: ethers.Signer['signTransaction'] = async ( - ...args: unknown[] - ) => { - return new Promise((resolve, reject) => { - wrapped.sendAsync( - { - method: 'eth_signTransaction', - params: args, - }, - (err, ok) => { - if (err) reject(err); - else resolve((ok).result as string); - }, - ); - }); - }; - return [signer, provider, rawSign]; - }); -}); -*/ - function runTestBattery( makeSigner: () => Promise< [ diff --git a/contracts/contracts/tests/Omnibus.sol b/contracts/contracts/tests/Omnibus.sol new file mode 100644 index 00000000..99774761 --- /dev/null +++ b/contracts/contracts/tests/Omnibus.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: UNLICENSED + +pragma solidity ^0.8.0; + +import {SignedQueriesTests} from "./SignedQueriesTests.sol"; +import {SemanticTests} from "./SemanticTests.sol"; + +contract Omnibus is SignedQueriesTests, SemanticTests { + uint256 public somevar; + + function setSomevar(uint256 value) external { + somevar = value; + } +} diff --git a/examples/ethersv5-ts-esm/package.json b/examples/ethersv5-ts-esm/package.json index 90f6a414..c95d4b65 100644 --- a/examples/ethersv5-ts-esm/package.json +++ b/examples/ethersv5-ts-esm/package.json @@ -7,7 +7,7 @@ "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/index.js" + "test": "tsc -b && pnpm node build/examples/ethersv5-ts-esm/src/index.js" }, "dependencies": { "@oasisprotocol/sapphire-paratime": "workspace:^", diff --git a/examples/ethersv5-ts-esm/src/TestErc20Token.ts b/examples/ethersv5-ts-esm/src/TestErc20Token.ts deleted file mode 100644 index fa0b9a00..00000000 --- a/examples/ethersv5-ts-esm/src/TestErc20Token.ts +++ /dev/null @@ -1,410 +0,0 @@ -export const TestErc20Token = { - "contractName": "TestErc20Token", - "abi": [ - { - "constant": true, - "inputs": [], - "name": "name", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "value", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "sender", - "type": "address" - }, - { - "name": "recipient", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "decimals", - "outputs": [ - { - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "addedValue", - "type": "uint256" - } - ], - "name": "increaseAllowance", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "account", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "mint", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "addMinter", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "renounceMinter", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "subtractedValue", - "type": "uint256" - } - ], - "name": "decreaseAllowance", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "recipient", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "isMinter", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "owner", - "type": "address" - }, - { - "name": "spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "account", - "type": "address" - } - ], - "name": "MinterAdded", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "account", - "type": "address" - } - ], - "name": "MinterRemoved", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "from", - "type": "address" - }, - { - "indexed": true, - "name": "to", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - } - ], - "bytecode": "0x60806040523480156200001157600080fd5b506040518060400160405280600a81526020017f5465737420546f6b656e000000000000000000000000000000000000000000008152506040518060400160405280600281526020017f545400000000000000000000000000000000000000000000000000000000000081525060126200009133620000da60201b60201c565b8251620000a690600490602086019062000256565b508151620000bc90600590602085019062000256565b506006805460ff191660ff9290921691909117905550620002fb9050565b620000f58160036200012c60201b62000b5c1790919060201c565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b6200014182826001600160e01b03620001d316565b15620001ae57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b60006001600160a01b03821662000236576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180620010856022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200029957805160ff1916838001178555620002c9565b82800160010185558215620002c9579182015b82811115620002c9578251825591602001919060010190620002ac565b50620002d7929150620002db565b5090565b620002f891905b80821115620002d75760008155600101620002e2565b90565b610d7a806200030b6000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a457c2d711610066578063a457c2d7146102db578063a9059cbb14610307578063aa271e1a14610333578063dd62ed3e14610359576100f5565b806370a082311461027d57806395d89b41146102a3578063983b2d56146102ab57806398650275146102d3576100f5565b806323b872dd116100d357806323b872dd146101d1578063313ce56714610207578063395093511461022557806340c10f1914610251576100f5565b806306fdde03146100fa578063095ea7b31461017757806318160ddd146101b7575b600080fd5b610102610387565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561018d57600080fd5b506001600160a01b03813516906020013561041d565b604080519115158252519081900360200190f35b6101bf610433565b60408051918252519081900360200190f35b6101a3600480360360608110156101e757600080fd5b506001600160a01b03813581169160208101359091169060400135610439565b61020f610490565b6040805160ff9092168252519081900360200190f35b6101a36004803603604081101561023b57600080fd5b506001600160a01b038135169060200135610499565b6101a36004803603604081101561026757600080fd5b506001600160a01b0381351690602001356104d5565b6101bf6004803603602081101561029357600080fd5b50356001600160a01b0316610525565b610102610540565b6102d1600480360360208110156102c157600080fd5b50356001600160a01b03166105a1565b005b6102d16105f1565b6101a3600480360360408110156102f157600080fd5b506001600160a01b0381351690602001356105fc565b6101a36004803603604081101561031d57600080fd5b506001600160a01b038135169060200135610638565b6101a36004803603602081101561034957600080fd5b50356001600160a01b0316610645565b6101bf6004803603604081101561036f57600080fd5b506001600160a01b038135811691602001351661065e565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b820191906000526020600020905b8154815290600101906020018083116103f657829003601f168201915b5050505050905090565b600061042a338484610689565b50600192915050565b60025490565b6000610446848484610775565b6001600160a01b038416600090815260016020908152604080832033808552925290912054610486918691610481908663ffffffff6108b716565b610689565b5060019392505050565b60065460ff1690565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff61091416565b60006104e033610645565b61051b5760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b61042a8383610975565b6001600160a01b031660009081526020819052604090205490565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b6105aa33610645565b6105e55760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b6105ee81610a65565b50565b6105fa33610aad565b565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff6108b716565b600061042a338484610775565b600061065860038363ffffffff610af516565b92915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166106ce5760405162461bcd60e51b8152600401808060200182810382526024815260200180610d226024913960400191505060405180910390fd5b6001600160a01b0382166107135760405162461bcd60e51b8152600401808060200182810382526022815260200180610c686022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166107ba5760405162461bcd60e51b8152600401808060200182810382526025815260200180610cfd6025913960400191505060405180910390fd5b6001600160a01b0382166107ff5760405162461bcd60e51b8152600401808060200182810382526023815260200180610c456023913960400191505060405180910390fd5b6001600160a01b038316600090815260208190526040902054610828908263ffffffff6108b716565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461085d908263ffffffff61091416565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282111561090e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008282018381101561096e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b0382166109d0576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6002546109e3908263ffffffff61091416565b6002556001600160a01b038216600090815260208190526040902054610a0f908263ffffffff61091416565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b610a7660038263ffffffff610b5c16565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b610abe60038263ffffffff610bdd16565b6040516001600160a01b038216907fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669290600090a250565b60006001600160a01b038216610b3c5760405162461bcd60e51b8152600401808060200182810382526022815260200180610cdb6022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b610b668282610af5565b15610bb8576040805162461bcd60e51b815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b610be78282610af5565b610c225760405162461bcd60e51b8152600401808060200182810382526021815260200180610cba6021913960400191505060405180910390fd5b6001600160a01b0316600090815260209190915260409020805460ff1916905556fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573734d696e746572526f6c653a2063616c6c657220646f6573206e6f74206861766520746865204d696e74657220726f6c65526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c65526f6c65733a206163636f756e7420697320746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a265627a7a72305820337bf5e979f127f42f6d97404492c0ad94b6efa80434ebee350caf56bb53f98f64736f6c63430005090032526f6c65733a206163636f756e7420697320746865207a65726f2061646472657373", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a457c2d711610066578063a457c2d7146102db578063a9059cbb14610307578063aa271e1a14610333578063dd62ed3e14610359576100f5565b806370a082311461027d57806395d89b41146102a3578063983b2d56146102ab57806398650275146102d3576100f5565b806323b872dd116100d357806323b872dd146101d1578063313ce56714610207578063395093511461022557806340c10f1914610251576100f5565b806306fdde03146100fa578063095ea7b31461017757806318160ddd146101b7575b600080fd5b610102610387565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561018d57600080fd5b506001600160a01b03813516906020013561041d565b604080519115158252519081900360200190f35b6101bf610433565b60408051918252519081900360200190f35b6101a3600480360360608110156101e757600080fd5b506001600160a01b03813581169160208101359091169060400135610439565b61020f610490565b6040805160ff9092168252519081900360200190f35b6101a36004803603604081101561023b57600080fd5b506001600160a01b038135169060200135610499565b6101a36004803603604081101561026757600080fd5b506001600160a01b0381351690602001356104d5565b6101bf6004803603602081101561029357600080fd5b50356001600160a01b0316610525565b610102610540565b6102d1600480360360208110156102c157600080fd5b50356001600160a01b03166105a1565b005b6102d16105f1565b6101a3600480360360408110156102f157600080fd5b506001600160a01b0381351690602001356105fc565b6101a36004803603604081101561031d57600080fd5b506001600160a01b038135169060200135610638565b6101a36004803603602081101561034957600080fd5b50356001600160a01b0316610645565b6101bf6004803603604081101561036f57600080fd5b506001600160a01b038135811691602001351661065e565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b820191906000526020600020905b8154815290600101906020018083116103f657829003601f168201915b5050505050905090565b600061042a338484610689565b50600192915050565b60025490565b6000610446848484610775565b6001600160a01b038416600090815260016020908152604080832033808552925290912054610486918691610481908663ffffffff6108b716565b610689565b5060019392505050565b60065460ff1690565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff61091416565b60006104e033610645565b61051b5760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b61042a8383610975565b6001600160a01b031660009081526020819052604090205490565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b6105aa33610645565b6105e55760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b6105ee81610a65565b50565b6105fa33610aad565b565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff6108b716565b600061042a338484610775565b600061065860038363ffffffff610af516565b92915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166106ce5760405162461bcd60e51b8152600401808060200182810382526024815260200180610d226024913960400191505060405180910390fd5b6001600160a01b0382166107135760405162461bcd60e51b8152600401808060200182810382526022815260200180610c686022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166107ba5760405162461bcd60e51b8152600401808060200182810382526025815260200180610cfd6025913960400191505060405180910390fd5b6001600160a01b0382166107ff5760405162461bcd60e51b8152600401808060200182810382526023815260200180610c456023913960400191505060405180910390fd5b6001600160a01b038316600090815260208190526040902054610828908263ffffffff6108b716565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461085d908263ffffffff61091416565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282111561090e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008282018381101561096e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b0382166109d0576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6002546109e3908263ffffffff61091416565b6002556001600160a01b038216600090815260208190526040902054610a0f908263ffffffff61091416565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b610a7660038263ffffffff610b5c16565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b610abe60038263ffffffff610bdd16565b6040516001600160a01b038216907fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669290600090a250565b60006001600160a01b038216610b3c5760405162461bcd60e51b8152600401808060200182810382526022815260200180610cdb6022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b610b668282610af5565b15610bb8576040805162461bcd60e51b815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b610be78282610af5565b610c225760405162461bcd60e51b8152600401808060200182810382526021815260200180610cba6021913960400191505060405180910390fd5b6001600160a01b0316600090815260209190915260409020805460ff1916905556fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573734d696e746572526f6c653a2063616c6c657220646f6573206e6f74206861766520746865204d696e74657220726f6c65526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c65526f6c65733a206163636f756e7420697320746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a265627a7a72305820337bf5e979f127f42f6d97404492c0ad94b6efa80434ebee350caf56bb53f98f64736f6c63430005090032", - "networks": {}, - "schemaVersion": "3.0.11", - "updatedAt": "2019-06-21T16:10:58.686Z", - "devdoc": { - "methods": { - "allowance(address,address)": { - "details": "See `IERC20.allowance`." - }, - "approve(address,uint256)": { - "details": "See `IERC20.approve`. * Requirements: * - `spender` cannot be the zero address." - }, - "balanceOf(address)": { - "details": "See `IERC20.balanceOf`." - }, - "decimals()": { - "details": "Returns the number of decimals used to get its user representation. For example, if `decimals` equals `2`, a balance of `505` tokens should be displayed to a user as `5,05` (`505 / 10 ** 2`). * Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. * > Note that this information is only used for _display_ purposes: it in no way affects any of the arithmetic of the contract, including `IERC20.balanceOf` and `IERC20.transfer`." - }, - "decreaseAllowance(address,uint256)": { - "details": "Atomically decreases the allowance granted to `spender` by the caller. * This is an alternative to `approve` that can be used as a mitigation for problems described in `IERC20.approve`. * Emits an `Approval` event indicating the updated allowance. * Requirements: * - `spender` cannot be the zero address. - `spender` must have allowance for the caller of at least `subtractedValue`." - }, - "increaseAllowance(address,uint256)": { - "details": "Atomically increases the allowance granted to `spender` by the caller. * This is an alternative to `approve` that can be used as a mitigation for problems described in `IERC20.approve`. * Emits an `Approval` event indicating the updated allowance. * Requirements: * - `spender` cannot be the zero address." - }, - "mint(address,uint256)": { - "details": "See `ERC20._mint`. * Requirements: * - the caller must have the `MinterRole`." - }, - "name()": { - "details": "Returns the name of the token." - }, - "symbol()": { - "details": "Returns the symbol of the token, usually a shorter version of the name." - }, - "totalSupply()": { - "details": "See `IERC20.totalSupply`." - }, - "transfer(address,uint256)": { - "details": "See `IERC20.transfer`. * Requirements: * - `recipient` cannot be the zero address. - the caller must have a balance of at least `amount`." - }, - "transferFrom(address,address,uint256)": { - "details": "See `IERC20.transferFrom`. * Emits an `Approval` event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of `ERC20`; * Requirements: - `sender` and `recipient` cannot be the zero address. - `sender` must have a balance of at least `value`. - the caller must have allowance for `sender`'s tokens of at least `amount`." - } - } - }, - "userdoc": { - "methods": {}, - "notice": "This is an implementation of an ERC20 token to be used in tests. It's a standard ERC20 implementation + `mint` (for testing). * This contract should not be used in production." - } - } as const; \ No newline at end of file diff --git a/examples/ethersv5-ts-esm/src/index.ts b/examples/ethersv5-ts-esm/src/index.ts index 800182e1..4a122f19 100644 --- a/examples/ethersv5-ts-esm/src/index.ts +++ b/examples/ethersv5-ts-esm/src/index.ts @@ -1,39 +1,83 @@ -import { wrap } from "@oasisprotocol/sapphire-paratime"; +import { wrapEthersProvider, wrapEthersSigner, wrap } from "@oasisprotocol/sapphire-paratime"; -import { BigNumber, ContractFactory, ethers } from "ethers"; +import { ContractFactory, Wallet, providers, Contract, ethers } from "ethers"; -import { TestErc20Token } from "./TestErc20Token.js"; import { assert } from "console"; +import OmnibusJSON from "../../../contracts/artifacts/contracts/tests/Omnibus.sol/Omnibus.json" assert { type: "json" }; + +async function testTheContract(contract:Contract, signerAddr?:string) +{ + const addr = await contract.callStatic["testSignedQueries()"]!(); + if( signerAddr ) { + assert( addr === signerAddr ); + } + else { + assert( addr === ethers.constants.AddressZero ); + } + + // XXX: Note that Ethers v5 has a 'workaround' that confuses types + // it makes no distinction between a reverted call returning reversion data + // vs a sucessful call return data with the expected return type. + /* + try { + await contract.callStatic['testCustomRevert()']!(); + assert(false); + } + catch(e:any) { + console.log(e); + assert(e.code == 'CALL_EXCEPTION'); + assert(e.errorName == 'CustomError'); + assert((e.errorArgs[0] as BigNumber).toHexString() == '0x1023456789abcdef1023456789abcdef1023456789abcdef1023456789abcdef'); + } + */ +} + async function main () { - const wallet = new ethers.Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'); + const wallet1 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'); + + const rawProvider1 = new providers.JsonRpcProvider('http://127.0.0.1:8545'); + const provider1 = wrapEthersProvider(rawProvider1); - const provider = wrap(new ethers.providers.JsonRpcProvider({ - url: 'http://127.0.0.1:8545', - })); + const rawProvider2 = new providers.JsonRpcProvider('http://127.0.0.1:8545'); - const signer = wrap(wallet.connect(provider)); + const signer1 = wrapEthersSigner(wallet1.connect(provider1)); - const fac = new ContractFactory(TestErc20Token.abi, TestErc20Token.bytecode, signer); + const fac = new ContractFactory(OmnibusJSON.abi, OmnibusJSON.bytecode, signer1); - console.log('Deploying'); const contract = await fac.deploy(); - console.log('Waiting for deployment'); const contractReceipt = await contract.deployed(); console.log('Deployed', contractReceipt.deployTransaction.hash); - console.log('Calling getAddress'); - const myAddr = await signer.getAddress(); + const signerAddr1 = await signer1.getAddress(); + + // signed queries will work + await testTheContract(contract, signerAddr1); + + const mkf = (x:any) => new ContractFactory(OmnibusJSON.abi, OmnibusJSON.bytecode, x); + + // Connect wallet to rawProvider, signed queries will work + await testTheContract( + mkf(wrapEthersSigner(wallet1.connect(rawProvider1))) + .attach(contract.address), + signerAddr1); + + // Use `wrap` instead of `wrapEthersSigner` + await testTheContract( + mkf(wrap(wallet1.connect(rawProvider1))) + .attach(contract.address), + signerAddr1); - console.log('Calling mint'); - const mintTx = await contract["mint(address,uint256)"](myAddr, 100) as ethers.providers.TransactionResponse; - assert(mintTx.data.length > 100); // TODO: ensure mintTx has encrypted calldata - console.log('mintTx', mintTx.hash); - await mintTx.wait(); + // wrapped provider, msg.sender == ZeroAddress + //testTheContract( // XXX: Note ethers v5 can't attach contract to provider, only signer! + // mkf(provider1) + // .attach(contract.address)); - console.log('Calling totalSupply'); - const totalSupply = await contract["totalSupply()"]() as BigNumber; - assert(totalSupply.eq(100)); + // Switch the signer to a different provider + await testTheContract( + mkf(signer1.connect(rawProvider2)) + .attach(contract.address), + signerAddr1); } await main (); diff --git a/examples/ethersv5-ts-esm/tsconfig.json b/examples/ethersv5-ts-esm/tsconfig.json index 13a1719c..9da514da 100644 --- a/examples/ethersv5-ts-esm/tsconfig.json +++ b/examples/ethersv5-ts-esm/tsconfig.json @@ -5,7 +5,8 @@ "outDir": "./build", "module": "NodeNext", "target": "ES2022", - "moduleResolution": "NodeNext" + "moduleResolution": "NodeNext", + "resolveJsonModule": true }, "include": [ "./src" diff --git a/examples/ethersv6-ts-esm/package.json b/examples/ethersv6-ts-esm/package.json index ccb1add3..08a6a6be 100644 --- a/examples/ethersv6-ts-esm/package.json +++ b/examples/ethersv6-ts-esm/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "build": "tsc -b", - "test": "tsc -b && pnpm node build/index.js" + "test": "tsc -b && pnpm node build/examples/ethersv6-ts-esm/src/index.js" }, "dependencies": { "@oasisprotocol/sapphire-paratime": "workspace:^", diff --git a/examples/ethersv6-ts-esm/src/TestErc20Token.ts b/examples/ethersv6-ts-esm/src/TestErc20Token.ts deleted file mode 100644 index fa0b9a00..00000000 --- a/examples/ethersv6-ts-esm/src/TestErc20Token.ts +++ /dev/null @@ -1,410 +0,0 @@ -export const TestErc20Token = { - "contractName": "TestErc20Token", - "abi": [ - { - "constant": true, - "inputs": [], - "name": "name", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "value", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "sender", - "type": "address" - }, - { - "name": "recipient", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "decimals", - "outputs": [ - { - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "addedValue", - "type": "uint256" - } - ], - "name": "increaseAllowance", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "account", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "mint", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "addMinter", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "renounceMinter", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "subtractedValue", - "type": "uint256" - } - ], - "name": "decreaseAllowance", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "recipient", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "isMinter", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "owner", - "type": "address" - }, - { - "name": "spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "account", - "type": "address" - } - ], - "name": "MinterAdded", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "account", - "type": "address" - } - ], - "name": "MinterRemoved", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "from", - "type": "address" - }, - { - "indexed": true, - "name": "to", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - } - ], - "bytecode": "0x60806040523480156200001157600080fd5b506040518060400160405280600a81526020017f5465737420546f6b656e000000000000000000000000000000000000000000008152506040518060400160405280600281526020017f545400000000000000000000000000000000000000000000000000000000000081525060126200009133620000da60201b60201c565b8251620000a690600490602086019062000256565b508151620000bc90600590602085019062000256565b506006805460ff191660ff9290921691909117905550620002fb9050565b620000f58160036200012c60201b62000b5c1790919060201c565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b6200014182826001600160e01b03620001d316565b15620001ae57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b60006001600160a01b03821662000236576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180620010856022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200029957805160ff1916838001178555620002c9565b82800160010185558215620002c9579182015b82811115620002c9578251825591602001919060010190620002ac565b50620002d7929150620002db565b5090565b620002f891905b80821115620002d75760008155600101620002e2565b90565b610d7a806200030b6000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a457c2d711610066578063a457c2d7146102db578063a9059cbb14610307578063aa271e1a14610333578063dd62ed3e14610359576100f5565b806370a082311461027d57806395d89b41146102a3578063983b2d56146102ab57806398650275146102d3576100f5565b806323b872dd116100d357806323b872dd146101d1578063313ce56714610207578063395093511461022557806340c10f1914610251576100f5565b806306fdde03146100fa578063095ea7b31461017757806318160ddd146101b7575b600080fd5b610102610387565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561018d57600080fd5b506001600160a01b03813516906020013561041d565b604080519115158252519081900360200190f35b6101bf610433565b60408051918252519081900360200190f35b6101a3600480360360608110156101e757600080fd5b506001600160a01b03813581169160208101359091169060400135610439565b61020f610490565b6040805160ff9092168252519081900360200190f35b6101a36004803603604081101561023b57600080fd5b506001600160a01b038135169060200135610499565b6101a36004803603604081101561026757600080fd5b506001600160a01b0381351690602001356104d5565b6101bf6004803603602081101561029357600080fd5b50356001600160a01b0316610525565b610102610540565b6102d1600480360360208110156102c157600080fd5b50356001600160a01b03166105a1565b005b6102d16105f1565b6101a3600480360360408110156102f157600080fd5b506001600160a01b0381351690602001356105fc565b6101a36004803603604081101561031d57600080fd5b506001600160a01b038135169060200135610638565b6101a36004803603602081101561034957600080fd5b50356001600160a01b0316610645565b6101bf6004803603604081101561036f57600080fd5b506001600160a01b038135811691602001351661065e565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b820191906000526020600020905b8154815290600101906020018083116103f657829003601f168201915b5050505050905090565b600061042a338484610689565b50600192915050565b60025490565b6000610446848484610775565b6001600160a01b038416600090815260016020908152604080832033808552925290912054610486918691610481908663ffffffff6108b716565b610689565b5060019392505050565b60065460ff1690565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff61091416565b60006104e033610645565b61051b5760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b61042a8383610975565b6001600160a01b031660009081526020819052604090205490565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b6105aa33610645565b6105e55760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b6105ee81610a65565b50565b6105fa33610aad565b565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff6108b716565b600061042a338484610775565b600061065860038363ffffffff610af516565b92915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166106ce5760405162461bcd60e51b8152600401808060200182810382526024815260200180610d226024913960400191505060405180910390fd5b6001600160a01b0382166107135760405162461bcd60e51b8152600401808060200182810382526022815260200180610c686022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166107ba5760405162461bcd60e51b8152600401808060200182810382526025815260200180610cfd6025913960400191505060405180910390fd5b6001600160a01b0382166107ff5760405162461bcd60e51b8152600401808060200182810382526023815260200180610c456023913960400191505060405180910390fd5b6001600160a01b038316600090815260208190526040902054610828908263ffffffff6108b716565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461085d908263ffffffff61091416565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282111561090e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008282018381101561096e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b0382166109d0576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6002546109e3908263ffffffff61091416565b6002556001600160a01b038216600090815260208190526040902054610a0f908263ffffffff61091416565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b610a7660038263ffffffff610b5c16565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b610abe60038263ffffffff610bdd16565b6040516001600160a01b038216907fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669290600090a250565b60006001600160a01b038216610b3c5760405162461bcd60e51b8152600401808060200182810382526022815260200180610cdb6022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b610b668282610af5565b15610bb8576040805162461bcd60e51b815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b610be78282610af5565b610c225760405162461bcd60e51b8152600401808060200182810382526021815260200180610cba6021913960400191505060405180910390fd5b6001600160a01b0316600090815260209190915260409020805460ff1916905556fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573734d696e746572526f6c653a2063616c6c657220646f6573206e6f74206861766520746865204d696e74657220726f6c65526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c65526f6c65733a206163636f756e7420697320746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a265627a7a72305820337bf5e979f127f42f6d97404492c0ad94b6efa80434ebee350caf56bb53f98f64736f6c63430005090032526f6c65733a206163636f756e7420697320746865207a65726f2061646472657373", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a457c2d711610066578063a457c2d7146102db578063a9059cbb14610307578063aa271e1a14610333578063dd62ed3e14610359576100f5565b806370a082311461027d57806395d89b41146102a3578063983b2d56146102ab57806398650275146102d3576100f5565b806323b872dd116100d357806323b872dd146101d1578063313ce56714610207578063395093511461022557806340c10f1914610251576100f5565b806306fdde03146100fa578063095ea7b31461017757806318160ddd146101b7575b600080fd5b610102610387565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561018d57600080fd5b506001600160a01b03813516906020013561041d565b604080519115158252519081900360200190f35b6101bf610433565b60408051918252519081900360200190f35b6101a3600480360360608110156101e757600080fd5b506001600160a01b03813581169160208101359091169060400135610439565b61020f610490565b6040805160ff9092168252519081900360200190f35b6101a36004803603604081101561023b57600080fd5b506001600160a01b038135169060200135610499565b6101a36004803603604081101561026757600080fd5b506001600160a01b0381351690602001356104d5565b6101bf6004803603602081101561029357600080fd5b50356001600160a01b0316610525565b610102610540565b6102d1600480360360208110156102c157600080fd5b50356001600160a01b03166105a1565b005b6102d16105f1565b6101a3600480360360408110156102f157600080fd5b506001600160a01b0381351690602001356105fc565b6101a36004803603604081101561031d57600080fd5b506001600160a01b038135169060200135610638565b6101a36004803603602081101561034957600080fd5b50356001600160a01b0316610645565b6101bf6004803603604081101561036f57600080fd5b506001600160a01b038135811691602001351661065e565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b820191906000526020600020905b8154815290600101906020018083116103f657829003601f168201915b5050505050905090565b600061042a338484610689565b50600192915050565b60025490565b6000610446848484610775565b6001600160a01b038416600090815260016020908152604080832033808552925290912054610486918691610481908663ffffffff6108b716565b610689565b5060019392505050565b60065460ff1690565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff61091416565b60006104e033610645565b61051b5760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b61042a8383610975565b6001600160a01b031660009081526020819052604090205490565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b6105aa33610645565b6105e55760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b6105ee81610a65565b50565b6105fa33610aad565b565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff6108b716565b600061042a338484610775565b600061065860038363ffffffff610af516565b92915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166106ce5760405162461bcd60e51b8152600401808060200182810382526024815260200180610d226024913960400191505060405180910390fd5b6001600160a01b0382166107135760405162461bcd60e51b8152600401808060200182810382526022815260200180610c686022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166107ba5760405162461bcd60e51b8152600401808060200182810382526025815260200180610cfd6025913960400191505060405180910390fd5b6001600160a01b0382166107ff5760405162461bcd60e51b8152600401808060200182810382526023815260200180610c456023913960400191505060405180910390fd5b6001600160a01b038316600090815260208190526040902054610828908263ffffffff6108b716565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461085d908263ffffffff61091416565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282111561090e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008282018381101561096e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b0382166109d0576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6002546109e3908263ffffffff61091416565b6002556001600160a01b038216600090815260208190526040902054610a0f908263ffffffff61091416565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b610a7660038263ffffffff610b5c16565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b610abe60038263ffffffff610bdd16565b6040516001600160a01b038216907fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669290600090a250565b60006001600160a01b038216610b3c5760405162461bcd60e51b8152600401808060200182810382526022815260200180610cdb6022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b610b668282610af5565b15610bb8576040805162461bcd60e51b815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b610be78282610af5565b610c225760405162461bcd60e51b8152600401808060200182810382526021815260200180610cba6021913960400191505060405180910390fd5b6001600160a01b0316600090815260209190915260409020805460ff1916905556fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573734d696e746572526f6c653a2063616c6c657220646f6573206e6f74206861766520746865204d696e74657220726f6c65526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c65526f6c65733a206163636f756e7420697320746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a265627a7a72305820337bf5e979f127f42f6d97404492c0ad94b6efa80434ebee350caf56bb53f98f64736f6c63430005090032", - "networks": {}, - "schemaVersion": "3.0.11", - "updatedAt": "2019-06-21T16:10:58.686Z", - "devdoc": { - "methods": { - "allowance(address,address)": { - "details": "See `IERC20.allowance`." - }, - "approve(address,uint256)": { - "details": "See `IERC20.approve`. * Requirements: * - `spender` cannot be the zero address." - }, - "balanceOf(address)": { - "details": "See `IERC20.balanceOf`." - }, - "decimals()": { - "details": "Returns the number of decimals used to get its user representation. For example, if `decimals` equals `2`, a balance of `505` tokens should be displayed to a user as `5,05` (`505 / 10 ** 2`). * Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. * > Note that this information is only used for _display_ purposes: it in no way affects any of the arithmetic of the contract, including `IERC20.balanceOf` and `IERC20.transfer`." - }, - "decreaseAllowance(address,uint256)": { - "details": "Atomically decreases the allowance granted to `spender` by the caller. * This is an alternative to `approve` that can be used as a mitigation for problems described in `IERC20.approve`. * Emits an `Approval` event indicating the updated allowance. * Requirements: * - `spender` cannot be the zero address. - `spender` must have allowance for the caller of at least `subtractedValue`." - }, - "increaseAllowance(address,uint256)": { - "details": "Atomically increases the allowance granted to `spender` by the caller. * This is an alternative to `approve` that can be used as a mitigation for problems described in `IERC20.approve`. * Emits an `Approval` event indicating the updated allowance. * Requirements: * - `spender` cannot be the zero address." - }, - "mint(address,uint256)": { - "details": "See `ERC20._mint`. * Requirements: * - the caller must have the `MinterRole`." - }, - "name()": { - "details": "Returns the name of the token." - }, - "symbol()": { - "details": "Returns the symbol of the token, usually a shorter version of the name." - }, - "totalSupply()": { - "details": "See `IERC20.totalSupply`." - }, - "transfer(address,uint256)": { - "details": "See `IERC20.transfer`. * Requirements: * - `recipient` cannot be the zero address. - the caller must have a balance of at least `amount`." - }, - "transferFrom(address,address,uint256)": { - "details": "See `IERC20.transferFrom`. * Emits an `Approval` event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of `ERC20`; * Requirements: - `sender` and `recipient` cannot be the zero address. - `sender` must have a balance of at least `value`. - the caller must have allowance for `sender`'s tokens of at least `amount`." - } - } - }, - "userdoc": { - "methods": {}, - "notice": "This is an implementation of an ERC20 token to be used in tests. It's a standard ERC20 implementation + `mint` (for testing). * This contract should not be used in production." - } - } as const; \ No newline at end of file diff --git a/examples/ethersv6-ts-esm/src/index.ts b/examples/ethersv6-ts-esm/src/index.ts index 51289948..1d11804f 100644 --- a/examples/ethersv6-ts-esm/src/index.ts +++ b/examples/ethersv6-ts-esm/src/index.ts @@ -1,39 +1,77 @@ -import { wrap } from "@oasisprotocol/sapphire-paratime"; +import { wrapEthersSigner, wrapEthersProvider, wrap } from "@oasisprotocol/sapphire-paratime"; -import { ContractFactory, JsonRpcProvider, ethers } from "ethers"; +import { ContractFactory, JsonRpcProvider, BaseContract, Wallet, ZeroAddress } from "ethers"; -import { TestErc20Token } from "./TestErc20Token.js"; import { assert } from "console"; -async function main () { - const wallet = new ethers.Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'); +import OmnibusJSON from "../../../contracts/artifacts/contracts/tests/Omnibus.sol/Omnibus.json" assert { type: "json" }; + +async function testTheContract(contract:BaseContract, signerAddr?:string) +{ + const addr = await contract.getFunction("testSignedQueries()")(); + if( signerAddr ) { + assert( addr === signerAddr ); + } + else { + assert( addr === ZeroAddress ); + } - const provider = wrap(new JsonRpcProvider('http://127.0.0.1:8545')); + try { + await contract.getFunction("testCustomRevert()").staticCall(); + assert(false); + } + catch(e:any) { + assert(e.code === 'CALL_EXCEPTION'); + assert(e.revert.name === 'CustomError'); + assert(e.revert.args[0] === 0x1023456789abcdef1023456789abcdef1023456789abcdef1023456789abcdefn); + } +} + +async function main () { + const wallet1 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'); + const rawProvider1 = new JsonRpcProvider('http://127.0.0.1:8545'); + const provider1 = wrapEthersProvider(rawProvider1); + const rawProvider2 = new JsonRpcProvider('http://127.0.0.1:8545'); - const signer = wrap(wallet.connect(provider)); + const signer1 = wrapEthersSigner(wallet1.connect(provider1)); - const fac = new ContractFactory(TestErc20Token.abi, TestErc20Token.bytecode, signer); + const fac = new ContractFactory(OmnibusJSON.abi, OmnibusJSON.bytecode, signer1); - console.log('Deploying'); const contract = await fac.deploy(); - console.log('Waiting for deployment'); const contractReceipt = await contract.waitForDeployment(); console.log('Deployed', contractReceipt.deploymentTransaction()?.hash); - console.log('Calling getAddress'); - const myAddr = await signer.getAddress(); + const signerAddr1 = await signer1.getAddress(); + + // signed queries will work + await testTheContract(contract, signerAddr1); + + const mkf = (x:any) => new ContractFactory(OmnibusJSON.abi, OmnibusJSON.bytecode, x); + + // Connect wallet to rawProvider, signed queries will work + await testTheContract( + mkf(wrapEthersSigner(wallet1.connect(rawProvider1))) + .attach(await contract.getAddress()), + signerAddr1); + + // Use `wrap` instead of `wrapEthersSigner` + await testTheContract( + mkf(wrap(wallet1.connect(rawProvider1))) + .attach(await contract.getAddress()), + signerAddr1); - console.log('Calling mint'); - const mintTx = await contract.getFunction("mint(address,uint256)")(myAddr, 100); - assert(mintTx.data.length > 100); // TODO: ensure mintTx has encrypted calldata - console.log('mintTx', mintTx.hash); - await mintTx.wait(); + // wrapped provider, msg.sender == ZeroAddress + await testTheContract( + mkf(provider1) + .attach(await contract.getAddress())); - console.log('Calling totalSupply'); - const totalSupply = await contract.getFunction("totalSupply()")() as bigint; - assert(totalSupply === 100n); + // Switch the signer to a different provider + await testTheContract( + mkf(signer1.connect(rawProvider2)) + .attach(await contract.getAddress()), + signerAddr1); } await main (); diff --git a/examples/ethersv6-ts-esm/tsconfig.json b/examples/ethersv6-ts-esm/tsconfig.json index 13a1719c..9da514da 100644 --- a/examples/ethersv6-ts-esm/tsconfig.json +++ b/examples/ethersv6-ts-esm/tsconfig.json @@ -5,7 +5,8 @@ "outDir": "./build", "module": "NodeNext", "target": "ES2022", - "moduleResolution": "NodeNext" + "moduleResolution": "NodeNext", + "resolveJsonModule": true }, "include": [ "./src" diff --git a/examples/web3js-ts-esm/package.json b/examples/web3js-ts-esm/package.json deleted file mode 100644 index a4f54c8b..00000000 --- a/examples/web3js-ts-esm/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "example-web3js-ts-esm", - "private": true, - "main": "lib/index.js", - "type": "module", - "scripts": { - "build": "tsc -b" - }, - "dependencies": { - "@oasisprotocol/sapphire-paratime": "workspace:^", - "web3": "4.3.0", - "typescript": "5.3.3" - }, - "devDependencies": { - "@types/node": "^17.0.10", - "@tsconfig/strictest": "2.0.2", - "ts-node": "10.9.2" - } - } diff --git a/examples/web3js-ts-esm/src/TestErc20Token.ts b/examples/web3js-ts-esm/src/TestErc20Token.ts deleted file mode 100644 index fa0b9a00..00000000 --- a/examples/web3js-ts-esm/src/TestErc20Token.ts +++ /dev/null @@ -1,410 +0,0 @@ -export const TestErc20Token = { - "contractName": "TestErc20Token", - "abi": [ - { - "constant": true, - "inputs": [], - "name": "name", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "value", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "sender", - "type": "address" - }, - { - "name": "recipient", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "decimals", - "outputs": [ - { - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "addedValue", - "type": "uint256" - } - ], - "name": "increaseAllowance", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "account", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "mint", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "addMinter", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "renounceMinter", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "spender", - "type": "address" - }, - { - "name": "subtractedValue", - "type": "uint256" - } - ], - "name": "decreaseAllowance", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "recipient", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "account", - "type": "address" - } - ], - "name": "isMinter", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "owner", - "type": "address" - }, - { - "name": "spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "account", - "type": "address" - } - ], - "name": "MinterAdded", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "account", - "type": "address" - } - ], - "name": "MinterRemoved", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "from", - "type": "address" - }, - { - "indexed": true, - "name": "to", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - } - ], - "bytecode": "0x60806040523480156200001157600080fd5b506040518060400160405280600a81526020017f5465737420546f6b656e000000000000000000000000000000000000000000008152506040518060400160405280600281526020017f545400000000000000000000000000000000000000000000000000000000000081525060126200009133620000da60201b60201c565b8251620000a690600490602086019062000256565b508151620000bc90600590602085019062000256565b506006805460ff191660ff9290921691909117905550620002fb9050565b620000f58160036200012c60201b62000b5c1790919060201c565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b6200014182826001600160e01b03620001d316565b15620001ae57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b60006001600160a01b03821662000236576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180620010856022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200029957805160ff1916838001178555620002c9565b82800160010185558215620002c9579182015b82811115620002c9578251825591602001919060010190620002ac565b50620002d7929150620002db565b5090565b620002f891905b80821115620002d75760008155600101620002e2565b90565b610d7a806200030b6000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a457c2d711610066578063a457c2d7146102db578063a9059cbb14610307578063aa271e1a14610333578063dd62ed3e14610359576100f5565b806370a082311461027d57806395d89b41146102a3578063983b2d56146102ab57806398650275146102d3576100f5565b806323b872dd116100d357806323b872dd146101d1578063313ce56714610207578063395093511461022557806340c10f1914610251576100f5565b806306fdde03146100fa578063095ea7b31461017757806318160ddd146101b7575b600080fd5b610102610387565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561018d57600080fd5b506001600160a01b03813516906020013561041d565b604080519115158252519081900360200190f35b6101bf610433565b60408051918252519081900360200190f35b6101a3600480360360608110156101e757600080fd5b506001600160a01b03813581169160208101359091169060400135610439565b61020f610490565b6040805160ff9092168252519081900360200190f35b6101a36004803603604081101561023b57600080fd5b506001600160a01b038135169060200135610499565b6101a36004803603604081101561026757600080fd5b506001600160a01b0381351690602001356104d5565b6101bf6004803603602081101561029357600080fd5b50356001600160a01b0316610525565b610102610540565b6102d1600480360360208110156102c157600080fd5b50356001600160a01b03166105a1565b005b6102d16105f1565b6101a3600480360360408110156102f157600080fd5b506001600160a01b0381351690602001356105fc565b6101a36004803603604081101561031d57600080fd5b506001600160a01b038135169060200135610638565b6101a36004803603602081101561034957600080fd5b50356001600160a01b0316610645565b6101bf6004803603604081101561036f57600080fd5b506001600160a01b038135811691602001351661065e565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b820191906000526020600020905b8154815290600101906020018083116103f657829003601f168201915b5050505050905090565b600061042a338484610689565b50600192915050565b60025490565b6000610446848484610775565b6001600160a01b038416600090815260016020908152604080832033808552925290912054610486918691610481908663ffffffff6108b716565b610689565b5060019392505050565b60065460ff1690565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff61091416565b60006104e033610645565b61051b5760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b61042a8383610975565b6001600160a01b031660009081526020819052604090205490565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b6105aa33610645565b6105e55760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b6105ee81610a65565b50565b6105fa33610aad565b565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff6108b716565b600061042a338484610775565b600061065860038363ffffffff610af516565b92915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166106ce5760405162461bcd60e51b8152600401808060200182810382526024815260200180610d226024913960400191505060405180910390fd5b6001600160a01b0382166107135760405162461bcd60e51b8152600401808060200182810382526022815260200180610c686022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166107ba5760405162461bcd60e51b8152600401808060200182810382526025815260200180610cfd6025913960400191505060405180910390fd5b6001600160a01b0382166107ff5760405162461bcd60e51b8152600401808060200182810382526023815260200180610c456023913960400191505060405180910390fd5b6001600160a01b038316600090815260208190526040902054610828908263ffffffff6108b716565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461085d908263ffffffff61091416565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282111561090e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008282018381101561096e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b0382166109d0576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6002546109e3908263ffffffff61091416565b6002556001600160a01b038216600090815260208190526040902054610a0f908263ffffffff61091416565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b610a7660038263ffffffff610b5c16565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b610abe60038263ffffffff610bdd16565b6040516001600160a01b038216907fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669290600090a250565b60006001600160a01b038216610b3c5760405162461bcd60e51b8152600401808060200182810382526022815260200180610cdb6022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b610b668282610af5565b15610bb8576040805162461bcd60e51b815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b610be78282610af5565b610c225760405162461bcd60e51b8152600401808060200182810382526021815260200180610cba6021913960400191505060405180910390fd5b6001600160a01b0316600090815260209190915260409020805460ff1916905556fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573734d696e746572526f6c653a2063616c6c657220646f6573206e6f74206861766520746865204d696e74657220726f6c65526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c65526f6c65733a206163636f756e7420697320746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a265627a7a72305820337bf5e979f127f42f6d97404492c0ad94b6efa80434ebee350caf56bb53f98f64736f6c63430005090032526f6c65733a206163636f756e7420697320746865207a65726f2061646472657373", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a457c2d711610066578063a457c2d7146102db578063a9059cbb14610307578063aa271e1a14610333578063dd62ed3e14610359576100f5565b806370a082311461027d57806395d89b41146102a3578063983b2d56146102ab57806398650275146102d3576100f5565b806323b872dd116100d357806323b872dd146101d1578063313ce56714610207578063395093511461022557806340c10f1914610251576100f5565b806306fdde03146100fa578063095ea7b31461017757806318160ddd146101b7575b600080fd5b610102610387565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561018d57600080fd5b506001600160a01b03813516906020013561041d565b604080519115158252519081900360200190f35b6101bf610433565b60408051918252519081900360200190f35b6101a3600480360360608110156101e757600080fd5b506001600160a01b03813581169160208101359091169060400135610439565b61020f610490565b6040805160ff9092168252519081900360200190f35b6101a36004803603604081101561023b57600080fd5b506001600160a01b038135169060200135610499565b6101a36004803603604081101561026757600080fd5b506001600160a01b0381351690602001356104d5565b6101bf6004803603602081101561029357600080fd5b50356001600160a01b0316610525565b610102610540565b6102d1600480360360208110156102c157600080fd5b50356001600160a01b03166105a1565b005b6102d16105f1565b6101a3600480360360408110156102f157600080fd5b506001600160a01b0381351690602001356105fc565b6101a36004803603604081101561031d57600080fd5b506001600160a01b038135169060200135610638565b6101a36004803603602081101561034957600080fd5b50356001600160a01b0316610645565b6101bf6004803603604081101561036f57600080fd5b506001600160a01b038135811691602001351661065e565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b820191906000526020600020905b8154815290600101906020018083116103f657829003601f168201915b5050505050905090565b600061042a338484610689565b50600192915050565b60025490565b6000610446848484610775565b6001600160a01b038416600090815260016020908152604080832033808552925290912054610486918691610481908663ffffffff6108b716565b610689565b5060019392505050565b60065460ff1690565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff61091416565b60006104e033610645565b61051b5760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b61042a8383610975565b6001600160a01b031660009081526020819052604090205490565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104135780601f106103e857610100808354040283529160200191610413565b6105aa33610645565b6105e55760405162461bcd60e51b8152600401808060200182810382526030815260200180610c8a6030913960400191505060405180910390fd5b6105ee81610a65565b50565b6105fa33610aad565b565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161042a918590610481908663ffffffff6108b716565b600061042a338484610775565b600061065860038363ffffffff610af516565b92915050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166106ce5760405162461bcd60e51b8152600401808060200182810382526024815260200180610d226024913960400191505060405180910390fd5b6001600160a01b0382166107135760405162461bcd60e51b8152600401808060200182810382526022815260200180610c686022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166107ba5760405162461bcd60e51b8152600401808060200182810382526025815260200180610cfd6025913960400191505060405180910390fd5b6001600160a01b0382166107ff5760405162461bcd60e51b8152600401808060200182810382526023815260200180610c456023913960400191505060405180910390fd5b6001600160a01b038316600090815260208190526040902054610828908263ffffffff6108b716565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461085d908263ffffffff61091416565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282111561090e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008282018381101561096e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b0382166109d0576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6002546109e3908263ffffffff61091416565b6002556001600160a01b038216600090815260208190526040902054610a0f908263ffffffff61091416565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b610a7660038263ffffffff610b5c16565b6040516001600160a01b038216907f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f690600090a250565b610abe60038263ffffffff610bdd16565b6040516001600160a01b038216907fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669290600090a250565b60006001600160a01b038216610b3c5760405162461bcd60e51b8152600401808060200182810382526022815260200180610cdb6022913960400191505060405180910390fd5b506001600160a01b03166000908152602091909152604090205460ff1690565b610b668282610af5565b15610bb8576040805162461bcd60e51b815260206004820152601f60248201527f526f6c65733a206163636f756e7420616c72656164792068617320726f6c6500604482015290519081900360640190fd5b6001600160a01b0316600090815260209190915260409020805460ff19166001179055565b610be78282610af5565b610c225760405162461bcd60e51b8152600401808060200182810382526021815260200180610cba6021913960400191505060405180910390fd5b6001600160a01b0316600090815260209190915260409020805460ff1916905556fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573734d696e746572526f6c653a2063616c6c657220646f6573206e6f74206861766520746865204d696e74657220726f6c65526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c65526f6c65733a206163636f756e7420697320746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a265627a7a72305820337bf5e979f127f42f6d97404492c0ad94b6efa80434ebee350caf56bb53f98f64736f6c63430005090032", - "networks": {}, - "schemaVersion": "3.0.11", - "updatedAt": "2019-06-21T16:10:58.686Z", - "devdoc": { - "methods": { - "allowance(address,address)": { - "details": "See `IERC20.allowance`." - }, - "approve(address,uint256)": { - "details": "See `IERC20.approve`. * Requirements: * - `spender` cannot be the zero address." - }, - "balanceOf(address)": { - "details": "See `IERC20.balanceOf`." - }, - "decimals()": { - "details": "Returns the number of decimals used to get its user representation. For example, if `decimals` equals `2`, a balance of `505` tokens should be displayed to a user as `5,05` (`505 / 10 ** 2`). * Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. * > Note that this information is only used for _display_ purposes: it in no way affects any of the arithmetic of the contract, including `IERC20.balanceOf` and `IERC20.transfer`." - }, - "decreaseAllowance(address,uint256)": { - "details": "Atomically decreases the allowance granted to `spender` by the caller. * This is an alternative to `approve` that can be used as a mitigation for problems described in `IERC20.approve`. * Emits an `Approval` event indicating the updated allowance. * Requirements: * - `spender` cannot be the zero address. - `spender` must have allowance for the caller of at least `subtractedValue`." - }, - "increaseAllowance(address,uint256)": { - "details": "Atomically increases the allowance granted to `spender` by the caller. * This is an alternative to `approve` that can be used as a mitigation for problems described in `IERC20.approve`. * Emits an `Approval` event indicating the updated allowance. * Requirements: * - `spender` cannot be the zero address." - }, - "mint(address,uint256)": { - "details": "See `ERC20._mint`. * Requirements: * - the caller must have the `MinterRole`." - }, - "name()": { - "details": "Returns the name of the token." - }, - "symbol()": { - "details": "Returns the symbol of the token, usually a shorter version of the name." - }, - "totalSupply()": { - "details": "See `IERC20.totalSupply`." - }, - "transfer(address,uint256)": { - "details": "See `IERC20.transfer`. * Requirements: * - `recipient` cannot be the zero address. - the caller must have a balance of at least `amount`." - }, - "transferFrom(address,address,uint256)": { - "details": "See `IERC20.transferFrom`. * Emits an `Approval` event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of `ERC20`; * Requirements: - `sender` and `recipient` cannot be the zero address. - `sender` must have a balance of at least `value`. - the caller must have allowance for `sender`'s tokens of at least `amount`." - } - } - }, - "userdoc": { - "methods": {}, - "notice": "This is an implementation of an ERC20 token to be used in tests. It's a standard ERC20 implementation + `mint` (for testing). * This contract should not be used in production." - } - } as const; \ No newline at end of file diff --git a/examples/web3js-ts-esm/src/index.ts b/examples/web3js-ts-esm/src/index.ts deleted file mode 100644 index fd5ada39..00000000 --- a/examples/web3js-ts-esm/src/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Web3 } from 'web3'; -import { TestErc20Token } from "./TestErc20Token.js"; -import { assert } from 'console'; -import { wrap } from "@oasisprotocol/sapphire-paratime"; - -async function main () { - - const provider = new Web3.providers.HttpProvider('http://127.0.0.1:3000'); - const wrappedProvider = wrap(provider); - const signer = new Web3(wrappedProvider); - - const account = signer.eth.accounts.wallet.add('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80').get(0)!; - console.log('account', account.address); - - const contract = new signer.eth.Contract(TestErc20Token.abi, undefined, { - gasPrice: '100000000000', - from: account.address - }); - - const deployed = await contract.deploy({ - data: TestErc20Token.bytecode - }).send({ - gas: '1185560' - }); - console.log('deployed', deployed.options.address); - - const mintTx = await deployed.methods.mint(account.address, 100n).send(); - console.log('mintTx', mintTx.transactionHash); - - const totalSupply = await deployed.methods.totalSupply().call() - assert(totalSupply === 100n); -} - -await main (); diff --git a/examples/web3js-ts-esm/tsconfig.json b/examples/web3js-ts-esm/tsconfig.json deleted file mode 100644 index 56003d8e..00000000 --- a/examples/web3js-ts-esm/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "@tsconfig/strictest/tsconfig.json", - "compilerOptions": { - "isolatedModules": false, - "outDir": "./build", - "module": "NodeNext", - "target": "ES2022", - "moduleResolution": "NodeNext" - }, - "include": [ - "./src" - ], - "ts-node": { - "esm": true - } -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c684390f..73a6236e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,16 +15,16 @@ importers: specifier: 0.0.5 version: 0.0.5 cborg: - specifier: ^1.10.2 + specifier: 1.10.2 version: 1.10.2 ethers: - specifier: ^6.10.0 + specifier: 6.10.0 version: 6.10.0 tweetnacl: specifier: 1.0.3 version: 1.0.3 type-fest: - specifier: ^2.19.0 + specifier: 2.19.0 version: 2.19.0 devDependencies: '@types/jest': @@ -438,28 +438,6 @@ importers: specifier: ^4.8.4 version: 4.9.5 - examples/web3js-ts-esm: - dependencies: - '@oasisprotocol/sapphire-paratime': - specifier: workspace:^ - version: link:../../clients/js - typescript: - specifier: 5.3.3 - version: 5.3.3 - web3: - specifier: 4.3.0 - version: 4.3.0(typescript@5.3.3) - devDependencies: - '@tsconfig/strictest': - specifier: 2.0.2 - version: 2.0.2 - '@types/node': - specifier: ^17.0.10 - version: 17.0.45 - ts-node: - specifier: 10.9.2 - version: 10.9.2(@types/node@17.0.45)(typescript@5.3.3) - integrations/hardhat: dependencies: '@oasisprotocol/sapphire-paratime': @@ -5234,18 +5212,6 @@ packages: typescript: 4.9.5 dev: false - /abitype@0.7.1(typescript@5.3.3): - resolution: {integrity: sha512-VBkRHTDZf9Myaek/dO3yMmOzB/y2s3Zo6nVU7yaw1G+TvCHAjwaJzNGN9yo4K5D8bU/VZXKP1EJpRhFr862PlQ==} - peerDependencies: - typescript: '>=4.9.4' - zod: ^3 >=3.19.1 - peerDependenciesMeta: - zod: - optional: true - dependencies: - typescript: 5.3.3 - dev: false - /abortcontroller-polyfill@1.7.5: resolution: {integrity: sha512-JMJ5soJWP18htbbxJjG7bG6yuI6pRhgJ0scHHTfkUjf6wjP912xZWvM+A4sJK3gqd9E8fcPbDnOefbA9Th/FIQ==} dev: true @@ -16496,6 +16462,7 @@ packages: resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} engines: {node: '>=14.17'} hasBin: true + dev: true /typical@4.0.0: resolution: {integrity: sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==} @@ -16963,26 +16930,6 @@ packages: - utf-8-validate dev: false - /web3-core@4.3.2: - resolution: {integrity: sha512-uIMVd/j4BgOnwfpY8ZT+QKubOyM4xohEhFZXz9xB8wimXWMMlYVlIK/TbfHqFolS9uOerdSGhsMbcK9lETae8g==} - engines: {node: '>=14', npm: '>=6.12.0'} - dependencies: - web3-errors: 1.1.4 - web3-eth-accounts: 4.1.0 - web3-eth-iban: 4.0.7 - web3-providers-http: 4.1.0 - web3-providers-ws: 4.0.7 - web3-types: 1.3.1 - web3-utils: 4.1.0 - web3-validator: 2.0.3 - optionalDependencies: - web3-providers-ipc: 4.0.7 - transitivePeerDependencies: - - bufferutil - - encoding - - utf-8-validate - dev: false - /web3-errors@1.1.4: resolution: {integrity: sha512-WahtszSqILez+83AxGecVroyZsMuuRT+KmQp4Si5P4Rnqbczno1k748PCrZTS1J4UCPmXMG2/Vt+0Bz2zwXkwQ==} engines: {node: '>=14', npm: '>=6.12.0'} @@ -17020,20 +16967,6 @@ packages: - zod dev: false - /web3-eth-abi@4.1.4(typescript@5.3.3): - resolution: {integrity: sha512-YLOBVVxxxLYKXjaiwZjEWYEnkMmmrm0nswZsvzSsINy/UgbWbzfoiZU+zn4YNWIEhORhx1p37iS3u/dP6VyC2w==} - engines: {node: '>=14', npm: '>=6.12.0'} - dependencies: - abitype: 0.7.1(typescript@5.3.3) - web3-errors: 1.1.4 - web3-types: 1.3.1 - web3-utils: 4.0.7 - web3-validator: 2.0.3 - transitivePeerDependencies: - - typescript - - zod - dev: false - /web3-eth-accounts@1.10.0: resolution: {integrity: sha512-wiq39Uc3mOI8rw24wE2n15hboLE0E9BsQLdlmsL4Zua9diDS6B5abXG0XhFcoNsXIGMWXVZz4TOq3u4EdpXF/Q==} engines: {node: '>=8.0.0'} @@ -17137,25 +17070,6 @@ packages: - zod dev: false - /web3-eth-contract@4.1.4(typescript@5.3.3): - resolution: {integrity: sha512-tJ4z6QLgtu8EQu2sXnLA7g427oxmngnbAUh+9kJKbP6Yep/oe+z79PqJv7H3MwqwUNW9T+/FeB2PnSQSyxz6ig==} - engines: {node: '>=14', npm: '>=6.12.0'} - dependencies: - web3-core: 4.3.2 - web3-errors: 1.1.4 - web3-eth: 4.3.1(typescript@5.3.3) - web3-eth-abi: 4.1.4(typescript@5.3.3) - web3-types: 1.3.1 - web3-utils: 4.1.0 - web3-validator: 2.0.3 - transitivePeerDependencies: - - bufferutil - - encoding - - typescript - - utf-8-validate - - zod - dev: false - /web3-eth-ens@1.10.0: resolution: {integrity: sha512-3hpGgzX3qjgxNAmqdrC2YUQMTfnZbs4GeLEmy8aCWziVwogbuqQZ+Gzdfrym45eOZodk+lmXyLuAdqkNlvkc1g==} engines: {node: '>=8.0.0'} @@ -17210,27 +17124,6 @@ packages: - zod dev: false - /web3-eth-ens@4.0.8(typescript@5.3.3): - resolution: {integrity: sha512-nj0JfeD45BbzVJcVYpUJnSo8iwDcY9CQ7CZhhIVVOFjvpMAPw0zEwjTvZEIQyCW61OoDG9xcBzwxe2tZoYhMRw==} - engines: {node: '>=14', npm: '>=6.12.0'} - dependencies: - '@adraffy/ens-normalize': 1.10.0 - web3-core: 4.3.2 - web3-errors: 1.1.4 - web3-eth: 4.3.1(typescript@5.3.3) - web3-eth-contract: 4.1.4(typescript@5.3.3) - web3-net: 4.0.7 - web3-types: 1.3.1 - web3-utils: 4.1.0 - web3-validator: 2.0.3 - transitivePeerDependencies: - - bufferutil - - encoding - - typescript - - utf-8-validate - - zod - dev: false - /web3-eth-iban@1.10.0: resolution: {integrity: sha512-0l+SP3IGhInw7Q20LY3IVafYEuufo4Dn75jAHT7c2aDJsIolvf2Lc6ugHkBajlwUneGfbRQs/ccYPQ9JeMUbrg==} engines: {node: '>=8.0.0'} @@ -17304,24 +17197,6 @@ packages: - zod dev: false - /web3-eth-personal@4.0.8(typescript@5.3.3): - resolution: {integrity: sha512-sXeyLKJ7ddQdMxz1BZkAwImjqh7OmKxhXoBNF3isDmD4QDpMIwv/t237S3q4Z0sZQamPa/pHebJRWVuvP8jZdw==} - engines: {node: '>=14', npm: '>=6.12.0'} - dependencies: - web3-core: 4.3.1 - web3-eth: 4.3.1(typescript@5.3.3) - web3-rpc-methods: 1.1.3 - web3-types: 1.3.1 - web3-utils: 4.0.7 - web3-validator: 2.0.3 - transitivePeerDependencies: - - bufferutil - - encoding - - typescript - - utf-8-validate - - zod - dev: false - /web3-eth@1.10.0: resolution: {integrity: sha512-Z5vT6slNMLPKuwRyKGbqeGYC87OAy8bOblaqRTgg94CXcn/mmqU7iPIlG4506YdcdK3x6cfEDG7B6w+jRxypKA==} engines: {node: '>=8.0.0'} @@ -17386,29 +17261,6 @@ packages: - zod dev: false - /web3-eth@4.3.1(typescript@5.3.3): - resolution: {integrity: sha512-zJir3GOXooHQT85JB8SrufE+Voo5TtXdjhf1D8IGXmxM8MrhI8AT+Pgt4siBTupJcu5hF17iGmTP/Nj2XnaibQ==} - engines: {node: '>=14', npm: '>=6.12.0'} - dependencies: - setimmediate: 1.0.5 - web3-core: 4.3.1 - web3-errors: 1.1.4 - web3-eth-abi: 4.1.4(typescript@5.3.3) - web3-eth-accounts: 4.1.0 - web3-net: 4.0.7 - web3-providers-ws: 4.0.7 - web3-rpc-methods: 1.1.3 - web3-types: 1.3.1 - web3-utils: 4.0.7 - web3-validator: 2.0.3 - transitivePeerDependencies: - - bufferutil - - encoding - - typescript - - utf-8-validate - - zod - dev: false - /web3-net@1.10.0: resolution: {integrity: sha512-NLH/N3IshYWASpxk4/18Ge6n60GEvWBVeM8inx2dmZJVmRI6SJIlUxbL8jySgiTn3MMZlhbdvrGo8fpUW7a1GA==} engines: {node: '>=8.0.0'} @@ -17555,19 +17407,6 @@ packages: - utf-8-validate dev: false - /web3-rpc-methods@1.1.4: - resolution: {integrity: sha512-LTFNg4LFaeU8K9ecuT8fHDp/LOXyxCneeZjCrRYIW1u82Ly52SrY55FIzMIISGoG/iT5Wh7UiHOB3CQsWLBmbQ==} - engines: {node: '>=14', npm: '>=6.12.0'} - dependencies: - web3-core: 4.3.2 - web3-types: 1.3.1 - web3-validator: 2.0.3 - transitivePeerDependencies: - - bufferutil - - encoding - - utf-8-validate - dev: false - /web3-shh@1.10.0: resolution: {integrity: sha512-uNUUuNsO2AjX41GJARV9zJibs11eq6HtOe6Wr0FtRUcj8SN6nHeYIzwstAvJ4fXA53gRqFMTxdntHEt9aXVjpg==} engines: {node: '>=8.0.0'} @@ -17722,34 +17561,6 @@ packages: - zod dev: false - /web3@4.3.0(typescript@5.3.3): - resolution: {integrity: sha512-YiLCsb5wmgJlSxRLzt7Z7H+CmlVVIKD8VaUQaZ+xKVG3Q7CpsO5Z6jmeKnlr6M9c6fDDsDnRM6G8g+nchZehbA==} - engines: {node: '>=14.0.0', npm: '>=6.12.0'} - dependencies: - web3-core: 4.3.2 - web3-errors: 1.1.4 - web3-eth: 4.3.1(typescript@5.3.3) - web3-eth-abi: 4.1.4(typescript@5.3.3) - web3-eth-accounts: 4.1.0 - web3-eth-contract: 4.1.4(typescript@5.3.3) - web3-eth-ens: 4.0.8(typescript@5.3.3) - web3-eth-iban: 4.0.7 - web3-eth-personal: 4.0.8(typescript@5.3.3) - web3-net: 4.0.7 - web3-providers-http: 4.1.0 - web3-providers-ws: 4.0.7 - web3-rpc-methods: 1.1.4 - web3-types: 1.3.1 - web3-utils: 4.1.0 - web3-validator: 2.0.3 - transitivePeerDependencies: - - bufferutil - - encoding - - typescript - - utf-8-validate - - zod - dev: false - /webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}