diff --git a/signers/signer-cosmos-snap/CHANGELOG.md b/signers/signer-cosmos-snap/CHANGELOG.md deleted file mode 100644 index c1013abba3..0000000000 --- a/signers/signer-cosmos-snap/CHANGELOG.md +++ /dev/null @@ -1,58 +0,0 @@ -# [0.14.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.13.0...signer-evm@0.14.0) (2023-08-03) - - - -# [0.13.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.12.0...signer-evm@0.13.0) (2023-08-01) - - - -# [0.9.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.8.0...signer-evm@0.9.0) (2023-07-31) - - -### Features - -* Support for WalletConnect 2 ([faedef0](https://github.com/rango-exchange/rango-client/commit/faedef0b5e6fc3c5ef881cbbe4ec05334cc1c910)) -* support safe wallet ([d04cbcd](https://github.com/rango-exchange/rango-client/commit/d04cbcd2a612755563512d9dff6f2312088d8b4d)) - - - -# [0.7.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.6.0...signer-evm@0.7.0) (2023-07-11) - - - -# [0.6.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.5.0...signer-evm@0.6.0) (2023-07-11) - - -### Bug Fixes - -* better parsing of evm rpc errors ([f23031a](https://github.com/rango-exchange/rango-client/commit/f23031ae14e6e841ee488591bd1bf58cfa7ca15b)) -* fix signer wait change network issues ([e453db6](https://github.com/rango-exchange/rango-client/commit/e453db6ccf7736e36e5ada0c29502be32254fe9c)) -* show tenderly error on call exception ([c218f49](https://github.com/rango-exchange/rango-client/commit/c218f49f3330706d9262b0cf3ec8e293e91e3729)) - - - -# [0.5.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.4.0...signer-evm@0.5.0) (2023-05-31) - - - -# [0.4.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.3.0...signer-evm@0.4.0) (2023-05-31) - - - -# [0.3.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.2.0...signer-evm@0.3.0) (2023-05-30) - - - -# [0.2.0](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.1.14...signer-evm@0.2.0) (2023-05-30) - - - -## [0.1.13](https://github.com/rango-exchange/rango-client/compare/signer-evm@0.1.12...signer-evm@0.1.13) (2023-05-15) - - -### Bug Fixes - -* update rango-types and fix notification bugs ([993f185](https://github.com/rango-exchange/rango-client/commit/993f185e0b8c5e5e15a2c65ba2d85d1f9c8daa90)) - - - diff --git a/signers/signer-cosmos-snap/readme.md b/signers/signer-cosmos-snap/readme.md deleted file mode 100644 index 1d66ea3e2b..0000000000 --- a/signers/signer-cosmos-snap/readme.md +++ /dev/null @@ -1 +0,0 @@ -# @rango-dev/signer-evm diff --git a/signers/signer-cosmos-snap/src/index.ts b/signers/signer-cosmos-snap/src/index.ts deleted file mode 100644 index 276520977d..0000000000 --- a/signers/signer-cosmos-snap/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { DefaultCosmosSnapSigner } from './signer'; diff --git a/wallets/provider-cosmos-snap/CHANGELOG.md b/wallets/provider-cosmos-snap/CHANGELOG.md new file mode 100644 index 0000000000..752d5d4d48 --- /dev/null +++ b/wallets/provider-cosmos-snap/CHANGELOG.md @@ -0,0 +1,51 @@ +# [0.14.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.13.0...provider-metamask@0.14.0) (2023-08-03) + + + +# [0.13.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.12.0...provider-metamask@0.13.0) (2023-08-01) + + + +# [0.9.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.8.0...provider-metamask@0.9.0) (2023-07-31) + + + +# [0.7.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.6.0...provider-metamask@0.7.0) (2023-07-11) + + + +# [0.6.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.5.0...provider-metamask@0.6.0) (2023-07-11) + + +### Reverts + +* Revert "support for rango-types cjs format" ([ed4e050](https://github.com/rango-exchange/rango-client/commit/ed4e050bfc0dcde7aeffa6b0d73b02080a5721eb)) +* Revert "support for rango-types cjs format" ([4f5f55f](https://github.com/rango-exchange/rango-client/commit/4f5f55f96e8daa329588b932b19c291c30f339c4)) + + + +# [0.5.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.4.0...provider-metamask@0.5.0) (2023-05-31) + + + +# [0.4.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.3.0...provider-metamask@0.4.0) (2023-05-31) + + + +# [0.3.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.2.0...provider-metamask@0.3.0) (2023-05-30) + + + +# [0.2.0](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.1.15...provider-metamask@0.2.0) (2023-05-30) + + + +## [0.1.14](https://github.com/rango-exchange/rango-client/compare/provider-metamask@0.1.13...provider-metamask@0.1.14) (2023-05-15) + + +### Bug Fixes + +* update rango-types and fix notification bugs ([993f185](https://github.com/rango-exchange/rango-client/commit/993f185e0b8c5e5e15a2c65ba2d85d1f9c8daa90)) + + + diff --git a/signers/signer-cosmos-snap/package.json b/wallets/provider-cosmos-snap/package.json similarity index 70% rename from signers/signer-cosmos-snap/package.json rename to wallets/provider-cosmos-snap/package.json index 1126ec42aa..8cdb10a235 100644 --- a/signers/signer-cosmos-snap/package.json +++ b/wallets/provider-cosmos-snap/package.json @@ -1,6 +1,6 @@ { - "name": "@rango-dev/signer-cosmos-snap", - "version": "0.17.0", + "name": "@rango-dev/provider-cosmos-snap", + "version": "0.17.1-next.1", "license": "MIT", "type": "module", "module": "./dist/index.js", @@ -14,15 +14,13 @@ "src" ], "scripts": { - "build": "node ../../scripts/build/command.mjs --path signers/signer-cosmos-snap", + "build": "node ../../scripts/build/command.mjs --path wallets/provider-cosmos-snap", "clean": "rimraf dist", "format": "prettier --write '{.,src}/**/*.{ts,tsx}'", - "lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore", - "test": "vitest", - "test:watch": "vitest --watch", - "test:coverage": "vitest run --coverage" + "lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore" }, "dependencies": { + "@rango-dev/wallets-shared": "^0.17.1-next.1", "rango-types": "^0.1.46", "@cosmjs/amino": "^0.31.3", "@cosmjs/proto-signing": "^0.30.1", diff --git a/wallets/provider-cosmos-snap/readme.md b/wallets/provider-cosmos-snap/readme.md new file mode 100644 index 0000000000..26e42e1f5b --- /dev/null +++ b/wallets/provider-cosmos-snap/readme.md @@ -0,0 +1 @@ +# @rango-dev/provider-cosmos-snap diff --git a/wallets/provider-metamask/src/snap.ts b/wallets/provider-cosmos-snap/src/helpers.ts similarity index 76% rename from wallets/provider-metamask/src/snap.ts rename to wallets/provider-cosmos-snap/src/helpers.ts index ab5ed43883..3df61bba90 100644 --- a/wallets/provider-metamask/src/snap.ts +++ b/wallets/provider-cosmos-snap/src/helpers.ts @@ -1,4 +1,22 @@ -export const DEFAULT_SNAP_ID = 'npm:@cosmsnap/snap'; +import { getCoinbaseInstance } from '@rango-dev/wallets-shared'; + +import { DEFAULT_SNAP_ID } from './signers/helpers'; + +export function metamask() { + const isCoinbaseWalletAvailable = !!getCoinbaseInstance(); + const { ethereum } = window; + + // Some wallets overriding the metamask. So we need to get it properly. + if (isCoinbaseWalletAvailable) { + // Getting intance from overrided structure from coinbase. + return getCoinbaseInstance('metamask'); + } + if (!!ethereum && ethereum.isMetaMask) { + return ethereum; + } + + return null; +} export const isCosmosSnapInstalled = async (instance: any) => { const result = await instance.request({ method: 'wallet_getSnaps' }); diff --git a/wallets/provider-cosmos-snap/src/index.ts b/wallets/provider-cosmos-snap/src/index.ts new file mode 100644 index 0000000000..06b684d399 --- /dev/null +++ b/wallets/provider-cosmos-snap/src/index.ts @@ -0,0 +1,82 @@ +import type { + CanEagerConnect, + CanSwitchNetwork, + Connect, + ProviderConnectResult, + Subscribe, + WalletInfo, +} from '@rango-dev/wallets-shared'; +import type { BlockchainMeta, SignerFactory } from 'rango-types'; + +import { + canEagerlyConnectToEvm, + subscribeToEvm, + WalletTypes, +} from '@rango-dev/wallets-shared'; +import { cosmosBlockchains } from 'rango-types'; + +import { + getAddresses, + installCosmosSnap, + isCosmosSnapInstalled, + metamask as metamask_instance, +} from './helpers'; +import signer from './signer'; + +const WALLET = WalletTypes.COSMOS_SNAP; + +export const config = { + type: WALLET, +}; + +export const getInstance = metamask_instance; +export const connect: Connect = async ({ instance }) => { + /* + * cosmos snap (It's optional) + * If the user approves to install Snap, we take the Cosmos addresses and add them to the accounts. + */ + await installCosmosSnap(instance); + const installed = await isCosmosSnapInstalled(instance); + let accounts: ProviderConnectResult[] = []; + if (installed) { + const addresses = await getAddresses(instance); + accounts = addresses.map((item) => ({ + accounts: [item.address], + chainId: item.chain_id, + })); + } + if (!accounts.length) { + throw new Error('You have rejected to install cosmos-snap'); + } + return accounts; +}; + +export const subscribe: Subscribe = subscribeToEvm; + +export const canSwitchNetworkTo: CanSwitchNetwork = () => false; + +export const getSigners: (provider: any) => SignerFactory = signer; + +export const canEagerConnect: CanEagerConnect = canEagerlyConnectToEvm; + +export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = ( + allBlockChains +) => { + const cosmos = cosmosBlockchains(allBlockChains); + return { + name: 'Cosmos Snap', + img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/metamask/icon.svg', + installLink: { + CHROME: + 'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en', + BRAVE: + 'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en', + + FIREFOX: 'https://addons.mozilla.org/en-US/firefox/addon/ether-metamask', + EDGE: 'https://microsoftedge.microsoft.com/addons/detail/metamask/ejbalbakoplchlghecdalmeeeajnimhm?hl=en-US', + DEFAULT: 'https://metamask.io/download/', + }, + color: '#dac7ae', + supportedChains: cosmos, + }; +}; diff --git a/wallets/provider-cosmos-snap/src/signer.ts b/wallets/provider-cosmos-snap/src/signer.ts new file mode 100644 index 0000000000..53bb2a77fc --- /dev/null +++ b/wallets/provider-cosmos-snap/src/signer.ts @@ -0,0 +1,11 @@ +import type { SignerFactory } from 'rango-types'; + +import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types'; + +import StarknetSigner from './signers/cosmos'; + +export default function getSigners(provider: any): SignerFactory { + const signers = new DefaultSignerFactory(); + signers.registerSigner(TxType.STARKNET, new StarknetSigner(provider)); + return signers; +} diff --git a/signers/signer-cosmos-snap/src/signer.ts b/wallets/provider-cosmos-snap/src/signers/cosmos.ts similarity index 93% rename from signers/signer-cosmos-snap/src/signer.ts rename to wallets/provider-cosmos-snap/src/signers/cosmos.ts index 4a5e496d54..6d8e3abd4c 100644 --- a/signers/signer-cosmos-snap/src/signer.ts +++ b/wallets/provider-cosmos-snap/src/signers/cosmos.ts @@ -3,7 +3,7 @@ import type { GenericSigner } from 'rango-types'; import type { CosmosTransaction } from 'rango-types/lib/api/main'; -import { DEFAULT_SNAP_ID, executeTransaction } from './helper'; +import { DEFAULT_SNAP_ID, executeTransaction } from './helpers'; export class DefaultCosmosSnapSigner implements GenericSigner diff --git a/signers/signer-cosmos-snap/src/helper.ts b/wallets/provider-cosmos-snap/src/signers/helpers.ts similarity index 100% rename from signers/signer-cosmos-snap/src/helper.ts rename to wallets/provider-cosmos-snap/src/signers/helpers.ts diff --git a/wallets/provider-cosmos-snap/src/types.ts b/wallets/provider-cosmos-snap/src/types.ts new file mode 100644 index 0000000000..e798b78d28 --- /dev/null +++ b/wallets/provider-cosmos-snap/src/types.ts @@ -0,0 +1,9 @@ +export interface AccContract { + addressSalt: string; + publicKey: string; // in hex + address: string; // in hex + addressIndex: number; + derivationPath: string; + deployTxnHash: string; // in hex + chainId: string; // in hex +} diff --git a/signers/signer-cosmos-snap/tsconfig.json b/wallets/provider-cosmos-snap/tsconfig.json similarity index 82% rename from signers/signer-cosmos-snap/tsconfig.json rename to wallets/provider-cosmos-snap/tsconfig.json index 579fb407b9..7f49cdfc54 100644 --- a/signers/signer-cosmos-snap/tsconfig.json +++ b/wallets/provider-cosmos-snap/tsconfig.json @@ -1,7 +1,7 @@ { // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs "extends": "../../tsconfig.lib.json", - "include": ["src", "types"], + "include": ["src", "types", "../../global-wallets-env.d.ts"], "compilerOptions": { "outDir": "dist", "rootDir": "./src", diff --git a/wallets/provider-metamask/src/index.ts b/wallets/provider-metamask/src/index.ts index 9381eca43f..e017da54eb 100644 --- a/wallets/provider-metamask/src/index.ts +++ b/wallets/provider-metamask/src/index.ts @@ -2,7 +2,6 @@ import type { CanEagerConnect, CanSwitchNetwork, Connect, - ProviderConnectResult, Subscribe, SwitchNetwork, WalletInfo, @@ -17,11 +16,10 @@ import { switchNetworkForEvm, WalletTypes, } from '@rango-dev/wallets-shared'; -import { cosmosBlockchains, evmBlockchains } from 'rango-types'; +import { evmBlockchains } from 'rango-types'; import { metamask as metamask_instance } from './helpers'; import signer from './signer'; -import { getAddresses, installCosmosSnap, isCosmosSnapInstalled } from './snap'; const WALLET = WalletTypes.META_MASK; @@ -31,29 +29,18 @@ export const config = { export const getInstance = metamask_instance; export const connect: Connect = async ({ instance }) => { - /* - * cosmos snap (It's optional) - * If the user approves to install Snap, we take the Cosmos addresses and add them to the accounts. - */ - await installCosmosSnap(instance); - const installed = await isCosmosSnapInstalled(instance); - let accounts: ProviderConnectResult[] = []; - if (installed) { - const addresses = await getAddresses(instance); - accounts = addresses.map((item) => ({ - accounts: [item.address], - chainId: item.chain_id, - })); - } /* * Note: We need to get `chainId` here, because for the first time * after opening the browser, wallet is locked, and don't give us accounts and chainId * on `check` phase, so `network` will be null. For this case we need to get chainId * whenever we are requesting accounts. */ - const evm = await getEvmAccounts(instance); - accounts = [...accounts, evm]; - return accounts; + const { accounts, chainId } = await getEvmAccounts(instance); + + return { + accounts, + chainId, + }; }; export const subscribe: Subscribe = subscribeToEvm; @@ -70,8 +57,6 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = ( allBlockChains ) => { const evms = evmBlockchains(allBlockChains); - const cosmos = cosmosBlockchains(allBlockChains); - return { name: 'MetaMask', img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/metamask/icon.svg', @@ -86,6 +71,6 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = ( DEFAULT: 'https://metamask.io/download/', }, color: '#dac7ae', - supportedChains: [...evms, ...cosmos], + supportedChains: evms, }; }; diff --git a/wallets/provider-metamask/src/signer.ts b/wallets/provider-metamask/src/signer.ts index 7c753e013c..13700368bc 100644 --- a/wallets/provider-metamask/src/signer.ts +++ b/wallets/provider-metamask/src/signer.ts @@ -1,13 +1,11 @@ import type { SignerFactory } from 'rango-types'; -import { DefaultCosmosSnapSigner } from '@rango-dev/signer-cosmos-snap'; import { DefaultEvmSigner } from '@rango-dev/signer-evm'; import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types'; export default function getSigners(provider: any): SignerFactory { const signers = new DefaultSignerFactory(); signers.registerSigner(TxType.EVM, new DefaultEvmSigner(provider)); - signers.registerSigner(TxType.COSMOS, new DefaultCosmosSnapSigner(provider)); return signers; } diff --git a/wallets/shared/src/rango.ts b/wallets/shared/src/rango.ts index 46cb0c1baa..8434e8e5d9 100644 --- a/wallets/shared/src/rango.ts +++ b/wallets/shared/src/rango.ts @@ -78,6 +78,7 @@ export enum WalletTypes { ENKRYPT = 'enkrypt', TAHO = 'taho', MY_TON_WALLET = 'mytonwallet', + COSMOS_SNAP = 'cosmos-snap', } export enum Networks {