diff --git a/.eslintrc.js b/.eslintrc.js index c5b77fe5..8fca8591 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,6 +19,7 @@ module.exports = { '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/camelcase': 'off', - '@typescript-eslint/ban-types': 'off' + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/ban-ts-comment': 'off', }, }; \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a3eb511..9d583fe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Changelog +## [1.6.4] - 2024-03-20 +### New +- Added `getTransactions` endpoint into DataUtils +### Breaking changes +- The parameters named `projectKey` and `graphqlEndpoint` have been removed in the PrimeSdk module + ## [1.6.3] - 2024-03-19 ### New - Added ArkaPaymaster as a sub-module diff --git a/README.md b/README.md index bc3646de..58aa758e 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ cloning down an example repo and setting up a dapp in your own environment. The mainnet bundler API key `eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9` is included in the example programs which is a public API key with rate limits, to get higher limits register to https://portal.etherspot.io +**Note: It is no longer necessary to include the `projectKey` parameter in the PrimeSdk.** + ## 📖 Documentation - [Quick Start](https://etherspot.fyi/getting-started) diff --git a/examples/01-get-address.ts b/examples/01-get-address.ts index 2785a1a7..c79967a9 100644 --- a/examples/01-get-address.ts +++ b/examples/01-get-address.ts @@ -8,7 +8,7 @@ async function main() { const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; const customBundlerUrl = ''; // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey, customBundlerUrl) }) // Testnets dont need apiKey on bundlerProvider + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey, customBundlerUrl) }) // Testnets dont need apiKey on bundlerProvider // get EtherspotWallet address... const address: string = await primeSdk.getCounterFactualAddress(); diff --git a/examples/02-transfer-funds.ts b/examples/02-transfer-funds.ts index 845dcee3..eeba7922 100644 --- a/examples/02-transfer-funds.ts +++ b/examples/02-transfer-funds.ts @@ -12,7 +12,7 @@ const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxM async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/03-transfer-erc20.ts b/examples/03-transfer-erc20.ts index ad661ded..cd3eb682 100644 --- a/examples/03-transfer-erc20.ts +++ b/examples/03-transfer-erc20.ts @@ -15,7 +15,7 @@ const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxM async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/04-transfer-nft.ts b/examples/04-transfer-nft.ts index b53a320b..7e7b0b7e 100644 --- a/examples/04-transfer-nft.ts +++ b/examples/04-transfer-nft.ts @@ -14,7 +14,7 @@ const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxM async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/07-transactions.ts b/examples/07-transactions.ts new file mode 100644 index 00000000..5746d1d4 --- /dev/null +++ b/examples/07-transactions.ts @@ -0,0 +1,21 @@ +import { DataUtils } from '../src'; +import * as dotenv from 'dotenv'; +dotenv.config(); + +const dataApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjI4ZWJiMGQ5YTMxYjQ3MmY4NmU4MWY2YTVhYzBhMzE1IiwiaCI6Im11cm11cjEyOCJ9'; + +async function main(): Promise { + // initializating Data service... + const dataService = new DataUtils(dataApiKey); + const account = '0xe05fb316eb8c4ba7288d43c1bd87be8a8d16761c'; + const transactions = await dataService.getTransactions({ + account, + chainId: 122, + }); + + console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet transactions:`, transactions); +} + +main() + .catch(console.error) + .finally(() => process.exit()); diff --git a/examples/12-add-guardians.ts b/examples/12-add-guardians.ts index 08f94846..ea5efa8c 100644 --- a/examples/12-add-guardians.ts +++ b/examples/12-add-guardians.ts @@ -12,7 +12,7 @@ async function main() { // initializating sdk... const primeSdk = new PrimeSdk( { privateKey: process.env.WALLET_PRIVATE_KEY }, - { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, + { chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, ); console.log('address: ', primeSdk.state.EOAAddress); diff --git a/examples/13-paymaster.ts b/examples/13-paymaster.ts index ac01217d..a70942d8 100644 --- a/examples/13-paymaster.ts +++ b/examples/13-paymaster.ts @@ -14,7 +14,7 @@ const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxM async function main() { // initializating sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { - chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', + chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) diff --git a/examples/14-zeroDev-address.ts b/examples/14-zeroDev-address.ts index facd2890..7926c5dc 100644 --- a/examples/14-zeroDev-address.ts +++ b/examples/14-zeroDev-address.ts @@ -7,8 +7,9 @@ dotenv.config(); async function main() { const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.ZERO_DEV, - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { + chainId: Number(process.env.CHAIN_ID), factoryWallet: Factory.ZERO_DEV, + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) // get ZeroDev address... diff --git a/examples/15-simpleAccount-address.ts b/examples/15-simpleAccount-address.ts index dbf83e1c..a23dc13f 100644 --- a/examples/15-simpleAccount-address.ts +++ b/examples/15-simpleAccount-address.ts @@ -7,8 +7,9 @@ dotenv.config(); async function main() { const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.SIMPLE_ACCOUNT, - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { + chainId: Number(process.env.CHAIN_ID), factoryWallet: Factory.SIMPLE_ACCOUNT, + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) // get SimpleAccount address... diff --git a/examples/16-paymaster-arka.ts b/examples/16-paymaster-arka.ts index bf18e170..5aac61f5 100644 --- a/examples/16-paymaster-arka.ts +++ b/examples/16-paymaster-arka.ts @@ -18,7 +18,7 @@ const queryString = `?apiKey=${arka_api_key}&chainId=${Number(process.env.CHAIN_ async function main() { // initializing sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { - chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', + chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) diff --git a/examples/19-paymaster-validUntil-validAfter.ts b/examples/19-paymaster-validUntil-validAfter.ts index 91ec382b..66aaa874 100644 --- a/examples/19-paymaster-validUntil-validAfter.ts +++ b/examples/19-paymaster-validUntil-validAfter.ts @@ -17,7 +17,7 @@ const queryString = `?apiKey=${arka_api_key}&chainId=${Number(process.env.CHAIN_ async function main() { // initializing sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { - chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) + chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/20-callGasLimit.ts b/examples/20-callGasLimit.ts index fb749804..fa1ca888 100644 --- a/examples/20-callGasLimit.ts +++ b/examples/20-callGasLimit.ts @@ -12,8 +12,9 @@ const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxM async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { + chainId: Number(process.env.CHAIN_ID), + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/21-get-multiple-accounts.ts b/examples/21-get-multiple-accounts.ts index 98ff06e9..4a067fb7 100644 --- a/examples/21-get-multiple-accounts.ts +++ b/examples/21-get-multiple-accounts.ts @@ -9,7 +9,7 @@ async function main() { // initializating sdk for index 0... const primeSdk = new PrimeSdk( { privateKey: process.env.WALLET_PRIVATE_KEY }, - { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, + { chainId: Number(process.env.CHAIN_ID), bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, ); // get EtherspotWallet address for index 0... @@ -19,7 +19,7 @@ async function main() { // initializating sdk for index 1... const primeSdk1 = new PrimeSdk( { privateKey: process.env.WALLET_PRIVATE_KEY }, - { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', index: 1, bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, + { chainId: Number(process.env.CHAIN_ID), index: 1, bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, ); // get EtherspotWallet address for index 1... diff --git a/examples/22-concurrent-userops.ts b/examples/22-concurrent-userops.ts index 5547fe5b..fda9e05b 100644 --- a/examples/22-concurrent-userops.ts +++ b/examples/22-concurrent-userops.ts @@ -13,8 +13,9 @@ const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxM async function main() { const provider = new providers.JsonRpcProvider(process.env.RPC_PROVIDER_URL); // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { + chainId: Number(process.env.CHAIN_ID), + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/23-bundlerApiKey.ts b/examples/23-bundlerApiKey.ts index bb845ebe..1586e335 100644 --- a/examples/23-bundlerApiKey.ts +++ b/examples/23-bundlerApiKey.ts @@ -7,8 +7,9 @@ dotenv.config(); async function main() { const etherspotBundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), etherspotBundlerApiKey) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { + chainId: Number(process.env.CHAIN_ID), + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), etherspotBundlerApiKey) }) // get EtherspotWallet address... diff --git a/examples/scripts/commands/erc20Transfer.ts b/examples/scripts/commands/erc20Transfer.ts index 909308a9..c9033cbb 100644 --- a/examples/scripts/commands/erc20Transfer.ts +++ b/examples/scripts/commands/erc20Transfer.ts @@ -12,7 +12,6 @@ export default async function main( amt: string, ) { const primeSdk = new PrimeSdk({ privateKey: config.signingKey }, { chainId: config.chainId, rpcProviderUrl: config.rpcProviderUrl }) - const address = await primeSdk.getCounterFactualAddress(); const provider = new ethers.providers.JsonRpcProvider(config.rpcProviderUrl); const token = ethers.utils.getAddress(tkn); diff --git a/examples/scripts/commands/transfer.ts b/examples/scripts/commands/transfer.ts index 77da0269..df1b4c6b 100644 --- a/examples/scripts/commands/transfer.ts +++ b/examples/scripts/commands/transfer.ts @@ -8,7 +8,6 @@ import { sleep } from "../../../src/sdk/common"; export default async function main(t: string, amt: string) { const primeSdk = new PrimeSdk({ privateKey: config.signingKey }, { chainId: config.chainId, rpcProviderUrl: config.rpcProviderUrl }) - const address = await primeSdk.getCounterFactualAddress(); const target = ethers.utils.getAddress(t); const value = ethers.utils.parseEther(amt); diff --git a/package-lock.json b/package-lock.json index 18b84c2e..93dcaee8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@etherspot/prime-sdk", - "version": "1.6.3", + "version": "1.6.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etherspot/prime-sdk", - "version": "1.6.3", + "version": "1.6.4", "license": "MIT", "dependencies": { "@apollo/client": "3.8.7", diff --git a/package.json b/package.json index 605581e6..051863e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.6.3", + "version": "1.6.4", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", @@ -27,6 +27,7 @@ "03-transfer-erc20": "./node_modules/.bin/ts-node ./examples/03-transfer-erc20", "05-get-account-balances": "./node_modules/.bin/ts-node ./examples/05-get-account-balances", "06-transaction": "./node_modules/.bin/ts-node ./examples/06-transaction", + "07-transactions": "./node_modules/.bin/ts-node ./examples/07-transactions", "08-nft-list": "./node_modules/.bin/ts-node ./examples/08-nft-list", "09-exchange": "./node_modules/.bin/ts-node ./examples/09-exchange", "10-advance-routes-lifi": "./node_modules/.bin/ts-node ./examples/10-advance-routes-lifi", @@ -42,7 +43,7 @@ "21-get-multiple-accounts": "./node_modules/.bin/ts-node ./examples/21-get-multiple-accounts", "22-concurrent-userops": "./node_modules/.bin/ts-node ./examples/22-concurrent-userops", "format": "prettier --write \"{src,test,examples}/**/*.ts\"", - "lint": "eslint \"{src,test}/**/*.ts\"", + "lint": "eslint \"{src,test,examples}/**/*.ts\"", "lint-fix": "npm run lint -- --fix", "prebuild": "rimraf ./dist", "build": "npm run compile", diff --git a/src/sdk/api/api.service.ts b/src/sdk/api/api.service.ts index da0399ce..c2302449 100644 --- a/src/sdk/api/api.service.ts +++ b/src/sdk/api/api.service.ts @@ -102,9 +102,7 @@ export class ApiService { const authLink = setContext(async () => { return { - headers: { - ['x-project-key']: this.options.projectKey, - }, + headers: {}, }; }); diff --git a/src/sdk/api/constants.ts b/src/sdk/api/constants.ts index 4b173e18..b950b96b 100644 --- a/src/sdk/api/constants.ts +++ b/src/sdk/api/constants.ts @@ -7,9 +7,6 @@ export const сacheSettings = { export const MethodTypes = { GET: 'GET', POST: 'POST', - PUT: 'PUT', - DELETE: 'DELETE', - PATCH: 'PATCH', }; export const BACKEND_API_ENDPOINT = 'https://rpc.etherspot.io/data-api'; @@ -17,7 +14,8 @@ export const BACKEND_API_ENDPOINT = 'https://rpc.etherspot.io/data-api'; export const API_ENDPOINTS = { GET_ACCOUNT_BALANCES: 'account/balances', GET_ACCOUNT_NFTS: 'account/nfts', - GET_TRANSACTION: 'transactions/transaction', + GET_TRANSACTION: 'transactions/transactionByHash', + GET_TRANSACTIONS: 'transactions', GET_ADVANCE_ROUTES_LIFI: 'exchange/getAdvanceRoutesLiFi', GET_STEP_TRANSACTIONS: 'exchange/getStepTransactions', GET_EXCHANGE_SUPPORTED_ASSETS: 'assets/exchangeSupportedAssets', diff --git a/src/sdk/api/interfaces.ts b/src/sdk/api/interfaces.ts index 8c78b346..a50cc818 100644 --- a/src/sdk/api/interfaces.ts +++ b/src/sdk/api/interfaces.ts @@ -2,7 +2,6 @@ import { FetchPolicy } from '@apollo/client/core'; export interface ApiOptions { host: string; - projectKey: string; port?: number; useSsl?: boolean; } diff --git a/src/sdk/base/VerifyingPaymasterAPI.ts b/src/sdk/base/VerifyingPaymasterAPI.ts index 683c9b63..5fbdab0f 100644 --- a/src/sdk/base/VerifyingPaymasterAPI.ts +++ b/src/sdk/base/VerifyingPaymasterAPI.ts @@ -1,12 +1,10 @@ import { ethers } from 'ethers'; import fetch from 'cross-fetch'; -import { Buffer } from 'buffer'; import { calcPreVerificationGas } from './calcPreVerificationGas'; import { PaymasterAPI } from './PaymasterAPI'; import { UserOperationStruct } from '../contracts/account-abstraction/contracts/core/BaseAccount'; import { toJSON } from '../common/OperationUtils'; -const SIG_SIZE = 65; const DUMMY_PAYMASTER_AND_DATA = '0x0101010101010101010101010101010101010101000000000000000000000000000000000000000000000000000001010101010100000000000000000000000000000000000000000000000000000000000000000101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101'; diff --git a/src/sdk/common/constants.ts b/src/sdk/common/constants.ts index f98825e4..27ad6ec0 100644 --- a/src/sdk/common/constants.ts +++ b/src/sdk/common/constants.ts @@ -4,7 +4,6 @@ export enum HeaderNames { AuthToken = 'x-auth-token', AnalyticsToken = 'x-analytics-token', - ProjectKey = 'x-project-key', ProjectMetadata = 'x-project-metadata', } diff --git a/src/sdk/data/classes/index.ts b/src/sdk/data/classes/index.ts index 7fe2e204..fc2bd0ce 100644 --- a/src/sdk/data/classes/index.ts +++ b/src/sdk/data/classes/index.ts @@ -23,3 +23,4 @@ export * from './token-list'; export * from './token-lists'; export * from './token-list-token'; export * from './paginated-tokens'; +export * from './transactions'; diff --git a/src/sdk/data/classes/transactions.ts b/src/sdk/data/classes/transactions.ts new file mode 100644 index 00000000..8fddb3bd --- /dev/null +++ b/src/sdk/data/classes/transactions.ts @@ -0,0 +1,71 @@ +import { BigNumber } from 'ethers'; +import { TransactionStatuses } from '../constants'; + +export class Transactions { + transactions: UserOpsTransaction[]; + pageInfo?: { + currentPage: number; + limit: number; + }; +} + +class UserOpsTransaction { + chainId: number; + sender: string; + target?: string | null; + transactionHash: string; + userOpHash: string; + actualGasCost: number; + actualGasUsed: number; + success: TransactionStatuses; + timestamp: number; + paymaster: string; + value: number; + blockExplorerUrl: string; + input: string; + nonce: number; + initCode?: string; + callData?: string; + accountGasLimits?: string; + gasFees?: string; + callGasLimit: BigNumber; + verificationGasLimit: BigNumber; + preVerificationGas: BigNumber; + maxFeePerGas: BigNumber; + maxPriorityFeePerGas: BigNumber; + paymasterAndData?: string; + signature?: string; + beneficiary?: string; + nativeTransfers?: NativeTransfersEntity[]; + erc20Transfers?: Erc20TransfersEntity[]; + nftTransfers?: NFTTransfersEntity[]; +} + +class Erc20TransfersEntity { + from: string; + to: string; + value: number; + asset?: string; + address: string; + decimal: number; +} + +class NativeTransfersEntity { + from: string; + to: string; + value: string; + asset?: string; + address: string; + decimal: number; + data: string; +} + +class NFTTransfersEntity { + from: string; + to: string; + value: number; + tokenId: number; + asset?: string; + category: string; + address: string; +} diff --git a/src/sdk/data/data.module.ts b/src/sdk/data/data.module.ts index 381672e5..2a4e3d76 100644 --- a/src/sdk/data/data.module.ts +++ b/src/sdk/data/data.module.ts @@ -1,7 +1,7 @@ import { BigNumber } from 'ethers'; import { Route } from '@lifi/sdk'; import { ObjectSubject } from '../common'; -import { AccountBalances, AdvanceRoutesLiFi, NftList, PaginatedTokens, RateData, StepTransactions, TokenList, TokenListToken, Transaction } from './classes'; +import { AccountBalances, AdvanceRoutesLiFi, NftList, PaginatedTokens, RateData, StepTransactions, TokenList, TokenListToken, Transaction, Transactions } from './classes'; import { RestApiService } from '../api'; import { API_ENDPOINTS, MethodTypes } from '../api/constants'; @@ -55,7 +55,24 @@ export class DataModule { return response.transaction; } catch (error) { throw new Error(error.message || 'Failed to get transaction'); + } + } + async getTransactions(account: string, chainId: number, page?: number, limit?: number): Promise { + try { + const queryParams = { + 'api-key': this.currentApi, + account, + chainId, + page, + limit, + }; + + const response = await this.apiService.makeRequest(API_ENDPOINTS.GET_TRANSACTIONS, MethodTypes.GET, queryParams); + + return response; + } catch (error) { + throw new Error(error.message || 'Failed to get transactions'); } } diff --git a/src/sdk/dataUtils.ts b/src/sdk/dataUtils.ts index f9a82cee..78df867e 100644 --- a/src/sdk/dataUtils.ts +++ b/src/sdk/dataUtils.ts @@ -1,13 +1,13 @@ import "reflect-metadata"; -import { AccountBalances, AdvanceRoutesLiFi, DataModule, NftList, PaginatedTokens, RateData, StepTransactions, TokenList, TokenListToken, Transaction } from "./data"; -import { FetchExchangeRatesDto, GetAccountBalancesDto, GetAdvanceRoutesLiFiDto, GetExchangeSupportedAssetsDto, GetNftListDto, GetStepTransactionsLiFiDto, GetTokenListDto, GetTokenListsDto, GetTransactionDto, validateDto } from "./dto"; +import { AccountBalances, AdvanceRoutesLiFi, DataModule, NftList, PaginatedTokens, RateData, StepTransactions, TokenList, TokenListToken, Transaction, Transactions } from "./data"; +import { FetchExchangeRatesDto, GetAccountBalancesDto, GetAdvanceRoutesLiFiDto, GetExchangeSupportedAssetsDto, GetNftListDto, GetStepTransactionsLiFiDto, GetTokenListDto, GetTokenListsDto, GetTransactionDto, GetTransactionsDto, validateDto } from "./dto"; import { BigNumber } from "ethers"; export class DataUtils { private dataModule: DataModule; - private readonly defaultDataAPiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjI4ZWJiMGQ5YTMxYjQ3MmY4NmU4MWY2YTVhYzBhMzE1IiwiaCI6Im11cm11cjEyOCJ9'; + private readonly defaultDataApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjI4ZWJiMGQ5YTMxYjQ3MmY4NmU4MWY2YTVhYzBhMzE1IiwiaCI6Im11cm11cjEyOCJ9'; constructor(apiKey?: string) { - this.dataModule = new DataModule(apiKey || this.defaultDataAPiKey); + this.dataModule = new DataModule(apiKey || this.defaultDataApiKey); } /** @@ -39,6 +39,24 @@ export class DataUtils { return this.dataModule.getTransaction(hash, chainId); } + /** + * gets transactions + * @param dto + * @return Promise + */ + async getTransactions(dto: GetTransactionsDto): Promise { + const { account, chainId, page, limit } = await validateDto(dto, GetTransactionsDto, { + addressKeys: ['account'], + }); + + return this.dataModule.getTransactions( + account, + chainId, + page, + limit, + ); + } + /** * gets NFT list belonging to account * @param dto diff --git a/src/sdk/dto/get-transactions.dto.ts b/src/sdk/dto/get-transactions.dto.ts new file mode 100644 index 00000000..3a314c4f --- /dev/null +++ b/src/sdk/dto/get-transactions.dto.ts @@ -0,0 +1,11 @@ +import { IsPositive } from 'class-validator'; +import { IsAddress } from './validators'; +import { PaginationDto } from './pagination.dto'; + +export class GetTransactionsDto extends PaginationDto { + @IsAddress() + account: string = null; + + @IsPositive() + chainId: number; +} diff --git a/src/sdk/dto/index.ts b/src/sdk/dto/index.ts index e0ec54cb..8de73be2 100644 --- a/src/sdk/dto/index.ts +++ b/src/sdk/dto/index.ts @@ -13,3 +13,4 @@ export * from './get-token-list.dto'; export * from './pagination.dto'; export * from './get-exchange-supported-assets.dto'; export * from './get-token-lists.dto'; +export * from './get-transactions.dto'; diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index 9b5c28a9..e8f4fecc 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -14,19 +14,12 @@ export enum Factory { export interface SdkOptions { chainId: number; - projectKey: string; bundlerProvider?: BundlerProviderLike; stateStorage?: StateStorage; rpcProviderUrl?: string; - graphqlEndpoint?: string; factoryWallet?: Factory; walletFactoryAddress?: string; entryPointAddress?: string; accountAddress?: string; index?: number; } - -export enum graphqlEndpoints { - QA = 'qa-etherspot.pillarproject.io', - PROD = 'etherspot.pillarproject.io' -} diff --git a/src/sdk/network/constants.ts b/src/sdk/network/constants.ts index 5d733eb3..d8a77099 100644 --- a/src/sdk/network/constants.ts +++ b/src/sdk/network/constants.ts @@ -93,7 +93,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io', }, [1001]: { chainId: 1001, @@ -106,7 +105,6 @@ export const Networks: { simpleAccount: '', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io', }, [80001]: { chainId: 80001, @@ -119,7 +117,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io', }, [84531]: { chainId: 84531, @@ -132,7 +129,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io', }, [84532]: { chainId: 84532, @@ -145,7 +141,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [11155111]: { chainId: 11155111, @@ -158,7 +153,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [10]: { chainId: 10, @@ -171,7 +165,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'etherspot.pillarproject.io', }, [137]: { chainId: 137, @@ -184,7 +177,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'etherspot.pillarproject.io', }, [42161]: { chainId: 42161, @@ -197,7 +189,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'etherspot.pillarproject.io', }, [8217]: { chainId: 8217, @@ -210,7 +201,6 @@ export const Networks: { simpleAccount: '', } }, - graphqlEndpoint: 'etherspot.pillarproject.io', }, [1]: { chainId: 1, @@ -223,7 +213,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'etherspot.pillarproject.io', }, [421613]: { chainId: 421613, @@ -236,7 +225,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io', }, [10200]: { chainId: 10200, @@ -249,7 +237,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io', }, [122]: { chainId: 122, @@ -262,7 +249,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [123]: { chainId: 123, @@ -275,7 +261,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [100]: { chainId: 100, @@ -288,7 +273,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'etherspot.pillarproject.io', }, [2357]: { chainId: 2357, @@ -301,7 +285,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [420]: { chainId: 420, @@ -314,7 +297,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io', }, [31]: { chainId: 31, @@ -327,7 +309,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [20197]: { chainId: 20197, @@ -340,7 +321,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [5000]: { chainId: 5000, @@ -353,7 +333,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [5001]: { chainId: 5001, @@ -366,7 +345,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '', }, [43114]: { chainId: 43114, @@ -379,7 +357,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'etherspot.pillarproject.io' }, [8453]: { chainId: 8453, @@ -392,7 +369,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '' }, [56]: { chainId: 56, @@ -405,7 +381,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'etherspot.pillarproject.io' }, [97]: { chainId: 97, @@ -418,7 +393,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io' }, [43113]: { chainId: 43113, @@ -431,7 +405,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: 'qa-etherspot.pillarproject.io' }, [59144]: { chainId: 59144, @@ -444,7 +417,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '' }, [59140]: { chainId: 59140, @@ -457,7 +429,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '' }, [114]: { chainId: 114, @@ -470,7 +441,6 @@ export const Networks: { simpleAccount: '', } }, - graphqlEndpoint: '' }, [14]: { chainId: 14, @@ -483,7 +453,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '' }, [534351]: { chainId: 534351, @@ -496,7 +465,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '' }, [534352]: { chainId: 534352, @@ -509,7 +477,6 @@ export const Networks: { simpleAccount: '0x9406Cc6185a346906296840746125a0E44976454', } }, - graphqlEndpoint: '' }, }; diff --git a/src/sdk/network/interfaces.ts b/src/sdk/network/interfaces.ts index e8525282..019b851f 100644 --- a/src/sdk/network/interfaces.ts +++ b/src/sdk/network/interfaces.ts @@ -16,5 +16,4 @@ export interface NetworkConfig { simpleAccount: string; }; }; - graphqlEndpoint?: string; }; diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index f60a79f4..b982adfb 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -11,7 +11,7 @@ import { Factory, PaymasterApi, SdkOptions } from './interfaces'; import { Network } from "./network"; import { BatchUserOpsRequest, Exception, getGasFee, onRampApiKey, openUrl, UserOpsRequest } from "./common"; import { BigNumber, BigNumberish, ethers, providers } from 'ethers'; -import { getNetworkConfig, Networks, onRamperAllNetworks } from './network/constants'; +import { Networks, onRamperAllNetworks } from './network/constants'; import { UserOperationStruct } from './contracts/account-abstraction/contracts/core/BaseAccount'; import { EtherspotWalletAPI, HttpRpcClient, VerifyingPaymasterAPI } from './base'; import { TransactionDetailsForUserOp, TransactionGasInfoForUserOp } from './base/TransactionDetailsForUserOp'; @@ -54,16 +54,11 @@ export class PrimeSdk { this.chainId = chainId; this.index = index ?? 0; - const networkConfig = getNetworkConfig(chainId); if (!optionsLike.bundlerProvider) { optionsLike.bundlerProvider = new EtherspotBundler(chainId); } - if (networkConfig) { - optionsLike.graphqlEndpoint = networkConfig.graphqlEndpoint; - } - this.factoryUsed = optionsLike.factoryWallet ?? Factory.ETHERSPOT; let provider;