diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..5716b8a740 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +# https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 +quote_type = double \ No newline at end of file diff --git a/.github/workflows/build-lint-typecheck-test.yaml b/.github/workflows/build-lint-typecheck-test.yaml index 13f3314e5e..83efbde9e0 100644 --- a/.github/workflows/build-lint-typecheck-test.yaml +++ b/.github/workflows/build-lint-typecheck-test.yaml @@ -47,7 +47,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: lts/* + node-version-file: .nvmrc registry-url: https://registry.npmjs.org/ cache: "yarn" diff --git a/.github/workflows/functional-tests-imx.yml b/.github/workflows/functional-tests-imx.yml index 39800f9cff..5ece8969f0 100644 --- a/.github/workflows/functional-tests-imx.yml +++ b/.github/workflows/functional-tests-imx.yml @@ -1,41 +1,41 @@ name: Functional Tests (IMX) on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: test: timeout-minutes: 60 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc - - name: Install root dependencies - run: npm install -g yarn && yarn install --immutable + - name: Install root dependencies + run: npm install -g yarn && yarn install --immutable - - name: Build SDK - run: yarn build + - name: Build SDK + run: yarn build - - name: Install functional tests dependencies - run: cd tests/func-tests/imx && yarn install --no-immutable + - name: Install functional tests dependencies + run: cd tests/func-tests/imx && yarn install --no-immutable - - name: Run tests - env: - NETWORK: sepolia - TEST_ALCHEMY_API_KEY: ${{ secrets.TEST_ALCHEMY_API_KEY }} - PUBLIC_API_URL: 'https://api.sandbox.x.immutable.com/v1' - TEST_STARK_CONTRACT_ADDRESS: '0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98' - TEST_REGISTRATION_CONTRACT_ADDRESS: '0xDbA6129C02E69405622fAdc3d5A7f8d23eac3b97' - TEST_TOKEN_ADDRESS: '0xfA5539fBEd27887EEbb2515672D80412D1A3ADa3' - TEST_WALLET1_PRIVATE_KEY: ${{ secrets.TEST_WALLET1_PRIVATE_KEY }} - TEST_WALLET1_STARK_PRIVATE_KEY: ${{ secrets.TEST_WALLET1_STARK_PRIVATE_KEY }} - TEST_WALLET2_PRIVATE_KEY: ${{ secrets.TEST_WALLET2_PRIVATE_KEY }} - TEST_WALLET2_STARK_PRIVATE_KEY: ${{ secrets.TEST_WALLET2_STARK_PRIVATE_KEY }} - TEST_WALLET_BANKER_PRIVATE_KEY: ${{ secrets.TEST_WALLET_BANKER_PRIVATE_KEY }} - TEST_WALLET_BANKER_STARK_PRIVATE_KEY: ${{ secrets.TEST_WALLET_BANKER_STARK_PRIVATE_KEY }} - TEST_STARKEX_BATCH_SIZE: 500 - run: cd tests/func-tests/imx && yarn test:ci + - name: Run tests + env: + NETWORK: sepolia + TEST_ALCHEMY_API_KEY: ${{ secrets.TEST_ALCHEMY_API_KEY }} + PUBLIC_API_URL: "https://api.sandbox.x.immutable.com/v1" + TEST_STARK_CONTRACT_ADDRESS: "0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98" + TEST_REGISTRATION_CONTRACT_ADDRESS: "0xDbA6129C02E69405622fAdc3d5A7f8d23eac3b97" + TEST_TOKEN_ADDRESS: "0xfA5539fBEd27887EEbb2515672D80412D1A3ADa3" + TEST_WALLET1_PRIVATE_KEY: ${{ secrets.TEST_WALLET1_PRIVATE_KEY }} + TEST_WALLET1_STARK_PRIVATE_KEY: ${{ secrets.TEST_WALLET1_STARK_PRIVATE_KEY }} + TEST_WALLET2_PRIVATE_KEY: ${{ secrets.TEST_WALLET2_PRIVATE_KEY }} + TEST_WALLET2_STARK_PRIVATE_KEY: ${{ secrets.TEST_WALLET2_STARK_PRIVATE_KEY }} + TEST_WALLET_BANKER_PRIVATE_KEY: ${{ secrets.TEST_WALLET_BANKER_PRIVATE_KEY }} + TEST_WALLET_BANKER_STARK_PRIVATE_KEY: ${{ secrets.TEST_WALLET_BANKER_STARK_PRIVATE_KEY }} + TEST_STARKEX_BATCH_SIZE: 500 + run: cd tests/func-tests/imx && yarn test:ci diff --git a/.github/workflows/functional-tests-zkevm.yml b/.github/workflows/functional-tests-zkevm.yml index 4dc8a71497..e0450e68ad 100644 --- a/.github/workflows/functional-tests-zkevm.yml +++ b/.github/workflows/functional-tests-zkevm.yml @@ -1,35 +1,35 @@ name: Functional Tests (zkEVM) on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: test: timeout-minutes: 60 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version-file: ".nvmrc" - - name: Install root dependencies - run: npm install -g yarn && yarn install --immutable + - name: Install root dependencies + run: npm install -g yarn && yarn install --immutable - - name: Build SDK - run: yarn build + - name: Build SDK + run: yarn build - - name: Install functional tests dependencies - run: cd tests/func-tests/zkevm && yarn install --no-immutable + - name: Install functional tests dependencies + run: cd tests/func-tests/zkevm && yarn install --no-immutable - - name: Run tests - env: - ZKEVM_ORDERBOOK_BANKER: ${{ secrets.ZKEVM_ORDERBOOK_BANKER }} - ZKEVM_ORDERBOOK_ERC721: '0xBE8B131f39825282Ace9eFf99C0Bb14972417b49' - SEAPORT_CONTRACT_ADDRESS: '0x7d117aA8BD6D31c4fa91722f246388f38ab1942c' - ZONE_CONTRACT_ADDRESS: '0x8831867E347AB87FA30199C5B695F0A31604Bb52' - ZKEVM_RPC_ENDPOINT: 'https://rpc.testnet.immutable.com' - ORDERBOOK_MR_API_URL: 'https://api.sandbox.immutable.com' - ZKEVM_CHAIN_NAME: 'imtbl-zkevm-testnet' - run: cd tests/func-tests/zkevm && yarn test:ci + - name: Run tests + env: + ZKEVM_ORDERBOOK_BANKER: ${{ secrets.ZKEVM_ORDERBOOK_BANKER }} + ZKEVM_ORDERBOOK_ERC721: "0xBE8B131f39825282Ace9eFf99C0Bb14972417b49" + SEAPORT_CONTRACT_ADDRESS: "0x7d117aA8BD6D31c4fa91722f246388f38ab1942c" + ZONE_CONTRACT_ADDRESS: "0x8831867E347AB87FA30199C5B695F0A31604Bb52" + ZKEVM_RPC_ENDPOINT: "https://rpc.testnet.immutable.com" + ORDERBOOK_MR_API_URL: "https://api.sandbox.immutable.com" + ZKEVM_CHAIN_NAME: "imtbl-zkevm-testnet" + run: cd tests/func-tests/zkevm && yarn test:ci diff --git a/.github/workflows/passport-sdk-sample-app-deployment.yaml b/.github/workflows/passport-sdk-sample-app-deployment.yaml index 71d36d9131..06c4bb8ddc 100644 --- a/.github/workflows/passport-sdk-sample-app-deployment.yaml +++ b/.github/workflows/passport-sdk-sample-app-deployment.yaml @@ -3,7 +3,7 @@ name: Passport SDK Sample App Deployment on: push: paths: - - 'packages/passport/**' + - "packages/passport/**" branches: - main workflow_dispatch: @@ -64,4 +64,4 @@ jobs: - name: Clear the cloudfront cache run: | - aws cloudfront create-invalidation --distribution-id ${{ secrets.CF_PASSPORT_PROD_DISTRIBUTION_ID }} --paths "/*" + aws cloudfront create-invalidation --distribution-id ${{ secrets.CF_PASSPORT_PROD_DISTRIBUTION_ID }} --paths "/*" diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 11ee8547e6..07b45dad30 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,9 +1,9 @@ name: Playwright Tests on: push: - branches: [ main, master ] + branches: [main, master] pull_request: - branches: [ main, master ] + branches: [main, master] jobs: test: timeout-minutes: 60 @@ -11,33 +11,33 @@ jobs: container: image: mcr.microsoft.com/playwright:v1.40.0-jammy steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version-file: samples/apps/ts-immutable-sample/.nvmrc - - name: Install root dependencies - run: npm install -g yarn && yarn install --immutable + - name: Install root dependencies + run: npm install -g yarn && yarn install --immutable - - name: Build SDK - run: yarn build + - name: Build SDK + run: yarn build - - name: Install sample apps dependencies - run: cd samples/apps/ts-immutable-sample && yarn install --no-immutable + - name: Install sample apps dependencies + run: cd samples/apps/ts-immutable-sample && yarn install --no-immutable - - name: Run Unit tests - run: cd samples/apps/ts-immutable-sample && yarn test - - - name: Run Playwright tests - env: - # Required for Firefox to run - # https://github.com/microsoft/playwright/issues/6500#issuecomment-838515115 - HOME: /root - working-directory: samples/apps/ts-immutable-sample - run: yarn playwright test - - uses: actions/upload-artifact@v3 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 + - name: Run Unit tests + run: cd samples/apps/ts-immutable-sample && yarn test + + - name: Run Playwright tests + env: + # Required for Firefox to run + # https://github.com/microsoft/playwright/issues/6500#issuecomment-838515115 + HOME: /root + working-directory: samples/apps/ts-immutable-sample + run: yarn playwright test + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/.github/workflows/publish-docs.yaml b/.github/workflows/publish-docs.yaml index 8894115b78..10f96cf820 100644 --- a/.github/workflows/publish-docs.yaml +++ b/.github/workflows/publish-docs.yaml @@ -46,8 +46,8 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: lts/* - cache: 'yarn' + node-version-file: .nvmrc + cache: "yarn" - name: Update SDK package.json version run: | diff --git a/.github/workflows/publish-major-version.yaml b/.github/workflows/publish-major-version.yaml index a54b3b9d14..c0d06c7e7e 100644 --- a/.github/workflows/publish-major-version.yaml +++ b/.github/workflows/publish-major-version.yaml @@ -59,7 +59,7 @@ jobs: id: allowed_actors_check # only allow certain SDK team members to run this workflow if: ${{ contains(fromJson(env.SDK_PUBLISH_MAJOR_VERSION_ACTORS), github.triggering_actor) }} - run: echo "ALLOWED_ACTOR=true" >> $GITHUB_OUTPUT + run: echo "ALLOWED_ACTOR=true" >> $GITHUB_OUTPUT - name: Allowed Actors Filter if: ${{ steps.allowed_actors_check.outputs.ALLOWED_ACTOR != 'true' }} @@ -85,8 +85,8 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: lts/* - cache: 'yarn' + node-version-file: .nvmrc + cache: "yarn" - name: Workout next version string run: | @@ -162,7 +162,7 @@ jobs: # Wait for 30 seconds to make sure the tag is available on GitHub - uses: GuillaumeFalourd/wait-sleep-action@v1 with: - time: '30' + time: "30" - name: Create GitHub Release id: gh_release diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 2dc9786160..8025d0732f 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -57,8 +57,8 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: lts/* - cache: 'yarn' + node-version-file: .nvmrc + cache: "yarn" - name: Workout next version string run: | @@ -136,7 +136,7 @@ jobs: # Wait for 30 seconds to make sure the tag is available on GitHub - uses: GuillaumeFalourd/wait-sleep-action@v1 with: - time: '30' + time: "30" - name: Create GitHub Release id: gh_release diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000000..1a2f5bd204 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/* \ No newline at end of file diff --git a/packages/checkout/widgets-lib/src/widgets/connect/components/WalletList.tsx b/packages/checkout/widgets-lib/src/widgets/connect/components/WalletList.tsx index 348aa18e8b..0ac644dac6 100644 --- a/packages/checkout/widgets-lib/src/widgets/connect/components/WalletList.tsx +++ b/packages/checkout/widgets-lib/src/widgets/connect/components/WalletList.tsx @@ -42,7 +42,7 @@ export function WalletList(props: WalletListProps) { const [wallets, setWallets] = useState([]); const { track } = useAnalytics(); - const selectWeb3Provider = useCallback((web3Provider: any) => { + const selectWeb3Provider = useCallback((web3Provider: any, providerName: string) => { connectDispatch({ payload: { type: ConnectActions.SET_PROVIDER, @@ -52,7 +52,7 @@ export function WalletList(props: WalletListProps) { connectDispatch({ payload: { type: ConnectActions.SET_WALLET_PROVIDER_NAME, - walletProviderName: WalletProviderName.METAMASK, + walletProviderName: providerName as WalletProviderName, }, }); }, []); @@ -62,7 +62,7 @@ export function WalletList(props: WalletListProps) { const connectCallback = async (ethereumProvider) => { if (ethereumProvider.connected && ethereumProvider.session) { const web3Provider = new Web3Provider(ethereumProvider as any); - selectWeb3Provider(web3Provider); + selectWeb3Provider(web3Provider, 'walletconnect'); const chainId = await web3Provider.getSigner().getChainId(); if (chainId !== targetChainId) { @@ -130,7 +130,7 @@ export function WalletList(props: WalletListProps) { walletProviderName, }); const web3Provider = providerResult.provider; - selectWeb3Provider(web3Provider); + selectWeb3Provider(web3Provider, walletProviderName); viewDispatch({ payload: { diff --git a/packages/internal/bridge/bridge-sample-app/.example.env b/packages/internal/bridge/bridge-sample-app/.example.env index a31aca5de0..e7bf44b5c3 100644 --- a/packages/internal/bridge/bridge-sample-app/.example.env +++ b/packages/internal/bridge/bridge-sample-app/.example.env @@ -59,4 +59,9 @@ FLOW_RATE_TOKEN_DECIMALS=18 # Values are in whole tokens and will be converted to wei using the decimals above FLOW_RATE_CAPACITY=15516 FLOW_RATE_REFILL_RATE=4.31 -FLOW_RATE_LARGE_TRANSFER_THRESHOLD=7758 \ No newline at end of file +FLOW_RATE_LARGE_TRANSFER_THRESHOLD=7758 + +# ISSUE SEPOLIA USDC ---------------------------------------------------------- + +SEPOLIA_USDC=0x40b87d235A5B010a20A241F15797C9debf1ecd01 +AMOUNT_10000=100 \ No newline at end of file diff --git a/packages/internal/bridge/bridge-sample-app/package.json b/packages/internal/bridge/bridge-sample-app/package.json index f65bbb181a..b213edce08 100644 --- a/packages/internal/bridge/bridge-sample-app/package.json +++ b/packages/internal/bridge/bridge-sample-app/package.json @@ -24,6 +24,7 @@ "fees": "node --loader ts-node/esm ./src/fees.ts", "flowRateInfo": "node --loader ts-node/esm ./src/flowRateInfo.ts", "getMapping": "node --loader ts-node/esm ./src/getMapping.ts", + "issueUSDC": "node --loader ts-node/esm ./src/issueUSDC.ts", "lint": "eslint ./src --ext .ts --max-warnings=0", "mapToken": "node --loader ts-node/esm ./src/mapToken.ts", "pending": "node --loader ts-node/esm ./src/pending.ts", diff --git a/packages/internal/bridge/bridge-sample-app/src/issueUSDC.ts b/packages/internal/bridge/bridge-sample-app/src/issueUSDC.ts new file mode 100644 index 0000000000..6ecc948b36 --- /dev/null +++ b/packages/internal/bridge/bridge-sample-app/src/issueUSDC.ts @@ -0,0 +1,49 @@ +/* eslint-disable no-console */ +import 'dotenv/config'; +import { ethers } from "ethers"; + +// @ts-ignore +import { setupForBridge } from './lib/utils.ts'; +// @ts-ignore +import { waitForReceipt } from './lib/helpers.ts'; +// @ts-ignore +import { USDC } from './lib/USDC.js'; + +async function issueUSDC() { + + const params = await setupForBridge(); + + if (!process.env.SEPOLIA_USDC) { + throw new Error('SEPOLIA_USDC not set'); + } + + if (!process.env.AMOUNT_10000) { + throw new Error('AMOUNT_10000 not set'); + } + + let sepoliaUSDCAddress: string = process.env.SEPOLIA_USDC; + let numberOfIssuances: number = parseInt(process.env.AMOUNT_10000); + + const usdcContract: ethers.Contract = new ethers.Contract(sepoliaUSDCAddress, USDC, params.rootProvider); + + let issuances = 0; + while (issuances < numberOfIssuances) { + issuances++; + console.log('issuances: ',issuances); + let resp = await usdcContract.connect(params.rootWallet).issueToken(); + console.log('resp: ',resp); + await waitForReceipt(resp.hash, params.rootProvider); + } + + console.log('done'); + +} + +(async () => { + try { + await issueUSDC() + console.log('Exiting successfully'); + } catch(err) { + console.error('Exiting with error', err) + } +})(); \ No newline at end of file diff --git a/packages/internal/bridge/bridge-sample-app/src/lib/USDC.ts b/packages/internal/bridge/bridge-sample-app/src/lib/USDC.ts new file mode 100644 index 0000000000..0d715e645f --- /dev/null +++ b/packages/internal/bridge/bridge-sample-app/src/lib/USDC.ts @@ -0,0 +1,402 @@ +export const USDC = [ + { + "inputs": [ + { + "internalType": "address", + "name": "initialOwner", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "allowance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "needed", + "type": "uint256" + } + ], + "name": "ERC20InsufficientAllowance", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "balance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "needed", + "type": "uint256" + } + ], + "name": "ERC20InsufficientBalance", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "approver", + "type": "address" + } + ], + "name": "ERC20InvalidApprover", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "ERC20InvalidReceiver", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "ERC20InvalidSender", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "ERC20InvalidSpender", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "issueToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +]; diff --git a/packages/internal/metrics/src/utils/checkEnv.ts b/packages/internal/metrics/src/utils/checkEnv.ts index 7421abae62..25ed31755a 100644 --- a/packages/internal/metrics/src/utils/checkEnv.ts +++ b/packages/internal/metrics/src/utils/checkEnv.ts @@ -1,4 +1,11 @@ -export function isTestEnvironment() { +import { isBrowser } from './browser'; +import { errorBoundary } from './errorBoundary'; + +function isTestEnvironmentFn() { + if (isBrowser()) { + return false; + } + if (typeof process === 'undefined') { return false; } @@ -7,3 +14,5 @@ export function isTestEnvironment() { // Just use process.env.CI for now. return process.env.JEST_WORKER_ID !== undefined; } + +export const isTestEnvironment = errorBoundary(isTestEnvironmentFn, false); diff --git a/packages/internal/metrics/src/utils/errorBoundary.test.ts b/packages/internal/metrics/src/utils/errorBoundary.test.ts index 32bd23a85b..b1000d45f5 100644 --- a/packages/internal/metrics/src/utils/errorBoundary.test.ts +++ b/packages/internal/metrics/src/utils/errorBoundary.test.ts @@ -26,4 +26,16 @@ describe('errorBoundary', () => { }; expect(errorBoundary(testFn)).not.toThrowError(); }); + it('should return the fallback result for a function that throws', () => { + const testFn = (): number => { + throw new Error('test'); + }; + expect(errorBoundary(testFn, 3)()).toEqual(3); + }); + it('should return the fallback result for an async function that throws', () => { + const testFn = async (): Promise => { + throw new Error('test'); + }; + expect(errorBoundary(testFn, Promise.resolve(3))()).resolves.toEqual(3); + }); }); diff --git a/packages/internal/metrics/src/utils/errorBoundary.ts b/packages/internal/metrics/src/utils/errorBoundary.ts index baf8c9c973..80859dbd77 100644 --- a/packages/internal/metrics/src/utils/errorBoundary.ts +++ b/packages/internal/metrics/src/utils/errorBoundary.ts @@ -1,4 +1,8 @@ -export function errorBoundary any>(fn: T): T { +export function errorBoundary any>( + fn: T, + fallbackResult?: ReturnType, +): T { const wrappedFunction = ((...args: Parameters): ReturnType => { try { // Execute the original function @@ -7,13 +11,13 @@ export function errorBoundary any>(fn: T): T { if (result instanceof Promise) { // Silent fail for now, in future // we can send errors to a logging service - return result.catch(() => undefined) as ReturnType; + return result.catch(() => fallbackResult) as ReturnType; } return result; } catch (error) { // As above, fail silently for now - return undefined as ReturnType; + return fallbackResult as ReturnType; } }) as T; diff --git a/packages/internal/metrics/src/utils/request.ts b/packages/internal/metrics/src/utils/request.ts index 8c3e376d67..dec1cf89f2 100644 --- a/packages/internal/metrics/src/utils/request.ts +++ b/packages/internal/metrics/src/utils/request.ts @@ -1,6 +1,6 @@ import axios from 'axios'; -const IMTBL_API = 'https://api.x.immutable.com'; +const IMTBL_API = 'https://api.immutable.com'; export async function post(path: string, data: any) { const client = axios.create({ diff --git a/packages/passport/sdk-sample-app/src/components/zkevm/EthSendTransactionExamples/NFTApproval.tsx b/packages/passport/sdk-sample-app/src/components/zkevm/EthSendTransactionExamples/NFTApproval.tsx index c587cfa3b5..6e1c169599 100644 --- a/packages/passport/sdk-sample-app/src/components/zkevm/EthSendTransactionExamples/NFTApproval.tsx +++ b/packages/passport/sdk-sample-app/src/components/zkevm/EthSendTransactionExamples/NFTApproval.tsx @@ -45,11 +45,13 @@ function NFTApproval({ disabled, handleExampleSubmitted }: RequestExampleProps) const [tokenId, setTokenId] = useState('1'); const [params, setParams] = useState([]); + const [isUnSafe, setIsUnSafe] = useState(false); const { zkEvmProvider } = usePassportProvider(); const handleSetApproveType = useCallback((e: React.ChangeEvent) => { setChoosedApproveType(e.target.value as ApproveType); }, []); + const sixteenNativeToken = '16000000000000000000'; useEffect(() => { const nftTokenId = tokenId.trim() === '' ? '1' : tokenId; @@ -57,11 +59,11 @@ function NFTApproval({ disabled, handleExampleSubmitted }: RequestExampleProps) const data = choosedApproveType === ApproveType.NFTApprove ? nftApproveContract.encodeFunctionData('approve', [toAddress, nftTokenId]) : nftApproveContract.encodeFunctionData('setApprovalForAll', [toAddress, true]); - + const transferAmount = isUnSafe ? sixteenNativeToken : '0'; setParams([{ from: fromAddress, to: erc721ContractAddress, - value: '0', + value: transferAmount, data, }]); } catch (err) { @@ -72,7 +74,7 @@ function NFTApproval({ disabled, handleExampleSubmitted }: RequestExampleProps) data: '0x', }]); } - }, [fromAddress, erc721ContractAddress, toAddress, tokenId, choosedApproveType, nftApproveContract]); + }, [fromAddress, erc721ContractAddress, toAddress, tokenId, choosedApproveType, nftApproveContract, isUnSafe]); useEffect(() => { const getAddress = async () => { @@ -174,6 +176,12 @@ function NFTApproval({ disabled, handleExampleSubmitted }: RequestExampleProps) /> )} + { setIsUnSafe(!isUnSafe); }} + type="checkbox" + id="check-is-unsafe" + label="is Unsafe?" + /> { switch (environment) { case EnvironmentNames.SANDBOX: - return '0xe9E96d1aad82562b7588F03f49aD34186f996478'; + return '0x7bbe61ba86dc1b128b7c6228a4834bf2c1394240'; case EnvironmentNames.PRODUCTION: return '0x52a6c53869ce09a731cd772f245b97a4401d3348'; case EnvironmentNames.DEV: diff --git a/packages/passport/sdk/package.json b/packages/passport/sdk/package.json index ef6f91e20f..f94cdcb1b5 100644 --- a/packages/passport/sdk/package.json +++ b/packages/passport/sdk/package.json @@ -31,7 +31,6 @@ "@types/axios": "^0.14.0", "@types/jest": "^29.4.3", "@types/jwt-encode": "^1.0.1", - "@types/node": "^18.14.2", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", "@typescript-eslint/eslint-plugin": "^5.57.1", diff --git a/packages/passport/sdk/src/utils/logger.ts b/packages/passport/sdk/src/utils/logger.ts index 4856f881b5..f812440c99 100644 --- a/packages/passport/sdk/src/utils/logger.ts +++ b/packages/passport/sdk/src/utils/logger.ts @@ -1,6 +1,9 @@ -const shouldLog: boolean = process?.env?.JEST_WORKER_ID === undefined; - const warn = (...args: any[]) => { + if (typeof process === 'undefined') { + return; + } + + const shouldLog: boolean = process?.env?.JEST_WORKER_ID === undefined; if (shouldLog) { // eslint-disable-next-line no-console console.warn(...args); diff --git a/sdk/rollup.config.js b/sdk/rollup.config.js index 9d36fa9aed..a513fa306a 100644 --- a/sdk/rollup.config.js +++ b/sdk/rollup.config.js @@ -132,7 +132,8 @@ export default [ __SDK_VERSION__: pkg.version, // This breaks in a dex dependency, so manually replacing it. - 'process.env.NODE_ENV': '"production"' + 'process.env.NODE_ENV': '"production"', + 'process': 'undefined' }), terser(), ], diff --git a/yarn.lock b/yarn.lock index db58f22c57..581c3d2ddc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3719,7 +3719,6 @@ __metadata: "@types/axios": ^0.14.0 "@types/jest": ^29.4.3 "@types/jwt-encode": ^1.0.1 - "@types/node": ^18.14.2 "@types/react": ^18.0.28 "@types/react-dom": ^18.0.11 "@typescript-eslint/eslint-plugin": ^5.57.1