diff --git a/.gitbook/SUMMARY.md b/.gitbook/SUMMARY.md index d26f82e85..007a5555e 100644 --- a/.gitbook/SUMMARY.md +++ b/.gitbook/SUMMARY.md @@ -86,6 +86,7 @@ - [Contracts](contracts/README.md) - [Injective Name Service](contracts/injective-name-service.md) - [Neptune Service](contracts/neptune-service.md) + - [CW20 to Bank & Market Order in One Transaction](contracts/cw20-convert-and-market-order-example.md) - [Building dApps](building-dapps/README.md) - [Configuring Nuxt](building-dapps/configuring-nuxt.md) - [Configuring React](building-dapps/configuring-react.md) diff --git a/.gitbook/contracts/README.md b/.gitbook/contracts/README.md index 03977430f..a120f2ee4 100644 --- a/.gitbook/contracts/README.md +++ b/.gitbook/contracts/README.md @@ -1,12 +1,13 @@ # Contracts -#### [What is CosmWasm?](./#what-is-cosmwasm-)[​](https://docs.injective.network/develop/guides/cosmwasm-dapps/#what-is-cosmwasm) +#### What is CosmWasm? CosmWasm is a novel smart contracting platform built for the Cosmos ecosystem. You can learn more about CosmWasm [here](https://docs.cosmwasm.com/docs/), or see the [CosmWasm Book](https://book.cosmwasm.com/index.html) for a guide on creating CosmWasm smart contracts. #### Specific Cosmwasm Contracts -| Topic | Description | -| --------------------------------------------------- | ---------------------- | -| [Injective Name Service](injective-name-service.md) | Injective Name Service | -| [Neptune Service](neptune-service.md) | Injective Name Service | +| Topic | Description | +| ------------------------------------------------------------------------------------------ | ---------------------- | +| [Injective Name Service](injective-name-service.md) | Injective Name Service | +| [Neptune Service](neptune-service.md) | Neptune Service | +| [CW20 to Bank & Market Order in One Transaction](cw20-convert-and-market-order-example.md) | Convert Cw20 Example | diff --git a/.gitbook/contracts/cw20-convert-and-market-order-example.md b/.gitbook/contracts/cw20-convert-and-market-order-example.md new file mode 100644 index 000000000..94f50c7e7 --- /dev/null +++ b/.gitbook/contracts/cw20-convert-and-market-order-example.md @@ -0,0 +1,54 @@ +# Convert Cw20 to Bank and Place Market Order In One Transaction Example + +This example helps you create messages to convert CW20 tokens to bank tokens on the Injective blockchain. This is particularly useful when you have CW20 tokens and need to convert them to their bank equivalents to perform operations like placing market orders. Note that this flow only works for cw20 tokens and their corresponding [factory tokens](../readme/application-concepts.md). + +This guide will walk you through: + +- Obtaining the user's CW20 token balance. +- Creating a message to convert CW20 tokens to bank tokens using ConvertCw20ToBankService +- Executing a market order using the converted bank balance and existing bank balance + +## Get User's CW20 Balance + +[Detailed here](../querying/querying-api/querying-indexer-explorer.md#fetch-cw20-balances) + +- Find the cw20 address and balance from the result set that you want to convert to a bank factory token + +## Create CW20 to Bank Conversion Message + +- create the `convertMsg` using the steps detailed [here](../readme/application-concepts#example-on-how-to-convert-cw20-to-a-factory-denom) in order to convert your cw20 token to a bank factory token. No need to submit the tsx yet. + +## Create a `MsgCreateSpotMarketOrder` message + +- Create the `msg` using the steps detailed in [MsgCreateSpotMarketOrder](../core-modules/exchange.md#msgcreatespotmarketorder). No need to submit the tsx yet. +- Note that the buy order you create will have access to your converted cw20 balance + existing bank balance. Example: + +```ts +const order = { + price: 1, + quantity: 10, +} +``` + +- If you had 5 Cw20 tokens and 5 bank tokens at a price of $1 each, then the order above will go through because we will convert the cw20 to bank before the chain executes this market order. This will be more clear in the next step. + +## Place a Market Order Using Converted CW20 Balance and your existing bank balance + +Now that you have both messages formatted, you can convert your cw20 tokens to bank factory tokens and then place a market order using the combined balance, all in one transaction + +```ts +import { MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts' +import { Network } from '@injectivelabs/networks' + +const privateKey = '0x...' +const injectiveAddress = 'inj1...' + +const txHash = await new MsgBroadcasterWithPk({ + privateKey, + network: Network.MainnetSentry, +}).broadcast({ + msgs: [convertMsg, msg], // the convert to bank message executes first, Then, you will have that additional balance to complete your market order in the following msg +}) + +console.log(txHash) +``` diff --git a/.gitbook/core-modules/auction.md b/.gitbook/core-modules/auction.md index 590839c8a..c1fbb70cb 100644 --- a/.gitbook/core-modules/auction.md +++ b/.gitbook/core-modules/auction.md @@ -68,7 +68,7 @@ How to use funds that are currently associated with your Injective Address in ba - If you have existing non-default subaccounts, you'll want to do a[ MsgDeposit ](exchange.md#msgdeposit)to one of your existing non-default subaccountIds and use that subaccountId as the `srcSubaccountId` below. - If you don't have existing non-default subaccounts, you can do a [MsgDeposit](exchange.md#msgdeposit) to a new default subaccountId, which would be done via importing `getSubaccountId` from `sdk-ts` and setting the `subaccountId` field in [MsgDeposit](exchange.md#msgdeposit) to `getSubaccountId(injectiveAddress, 1)`. -For more info, check out the [burn auction pool docs](https://docs.injective.network/develop/tech-concepts/auction_pool/). +For more info, check out the [burn auction pool docs](https://docs.injective.network/developers/modules/injective/auction). ```ts import { diff --git a/.gitbook/readme/application-concepts.md b/.gitbook/readme/application-concepts.md index defff8ec0..80c6f7279 100644 --- a/.gitbook/readme/application-concepts.md +++ b/.gitbook/readme/application-concepts.md @@ -11,7 +11,10 @@ Combined with the `CW20AdapterContract` which acts as a creator, we allow CW20 a Example on how to redeem a factory denom to CW20: ```ts -import { MsgExecuteContractCompat, ExecArgCW20AdapterRedeemAndTransfer } from '@injectivelabs/sdk-ts' +import { + MsgExecuteContractCompat, + ExecArgCW20AdapterRedeemAndTransfer, +} from '@injectivelabs/sdk-ts' const CW20_ADAPTER_CONTRACT = 'inj...' const contractCw20Address = 'inj...' @@ -22,20 +25,23 @@ const message = MsgExecuteContractCompat.fromJSON({ contractAddress: CW20_ADAPTER_CONTRACT, funds: { denom: `factory/${CW20_ADAPTER_CONTRACT}/${contractCw20Address}`, - amount: actualAmount.toFixed() + amount: actualAmount.toFixed(), }, execArgs: ExecArgCW20AdapterRedeemAndTransfer.fromJSON({ - recipient: injectiveAddress - }) + recipient: injectiveAddress, + }), }) // Then pack the message in a transaction, sign it and broadcast to the chain ``` -Example on how to convert CW20 to a factory denom: +### Example on how to convert CW20 to a factory denom: ```ts -import { MsgExecuteContractCompat, ExecArgCW20Send } from '@injectivelabs/sdk-ts' +import { + ExecArgCW20Send, + MsgExecuteContractCompat, +} from '@injectivelabs/sdk-ts' const CW20_ADAPTER_CONTRACT = 'inj...' const contractCw20Address = 'inj...' @@ -47,8 +53,8 @@ const message = MsgExecuteContractCompat.fromJSON({ sender: injectiveAddress, execArgs: ExecArgCW20Send.fromJSON({ amount, - contractAddress: CW20_ADAPTER_CONTRACT - }) + contractAddress: CW20_ADAPTER_CONTRACT, + }), }) // Then pack the message in a transaction, sign it and broadcast to the chain diff --git a/.gitbook/transactions/README.md b/.gitbook/transactions/README.md index e3da6f9fa..1aa3b3265 100644 --- a/.gitbook/transactions/README.md +++ b/.gitbook/transactions/README.md @@ -1,6 +1,6 @@ # Transactions -_Pre-requisite reading:_ [Cosmos SDK Transactions](https://docs.cosmos.network/main/core/transactions.html) +_Pre-requisite reading:_ [Cosmos SDK Transactions](https://docs.cosmos.network/main/learn/advanced/transactions) State changes on Injective can be done through transactions. Users create transactions, sign them and broadcast them to Injective. diff --git a/packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts b/packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts index bf650f11b..8f19b4a64 100644 --- a/packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts +++ b/packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts @@ -1,5 +1,7 @@ -import { generateArbitrarySignDoc } from '../tx/index.js' +import { verifyMessage, Wallet } from 'ethers' +import { toUtf8 } from '../../utils' import { PrivateKey } from './PrivateKey.js' +import { generateArbitrarySignDoc } from '../tx/index.js' const pk = process.env.TEST_PRIVATE_KEY as string const seedPhase = process.env.TEST_SEED_PHASE as string @@ -117,6 +119,32 @@ describe('PrivateKey', () => { // }) + it('returns true when checking a pk signature against the signer public key', async () => { + const message = 'this is a test message' + + const wallet = new Wallet(pk) + const ethersSignature = await wallet.signMessage(message) + + const privateKey = PrivateKey.fromHex(pk) + const publicKey = privateKey.toHex() + + const privKeySignatureArray = privateKey.sign( + Buffer.from(toUtf8(message), 'utf-8'), + ) + const privKeySignature = `0x${Buffer.from(privKeySignatureArray).toString( + 'hex', + )}` + + const ethersVerifiedSigner = verifyMessage(message, ethersSignature) + const ethersSignatureVerifiedCorrectly = ethersVerifiedSigner === publicKey + expect(ethersSignatureVerifiedCorrectly).toBe(true) + + const privKeyVerifiedSigner = verifyMessage(message, privKeySignature) + const privKeySignatureVerifiedCorrectly = + privKeyVerifiedSigner === publicKey + expect(privKeySignatureVerifiedCorrectly).toBe(true) + }) + it('returns true when verifying arbitrary message', async () => { const privateKey = PrivateKey.fromHex(pk) diff --git a/packages/utils/src/formatters.ts b/packages/utils/src/formatters.ts index 0514ed5fe..ee9f43948 100644 --- a/packages/utils/src/formatters.ts +++ b/packages/utils/src/formatters.ts @@ -37,3 +37,6 @@ export const snakeToPascal = (str: string): string => { ) .join('/') } + +export const capitalize = (str: string): string => + str[0].toUpperCase() + str.slice(1) diff --git a/packages/wallet-ts/src/strategies/wallet-strategy/strategies/Ledger/Base.ts b/packages/wallet-ts/src/strategies/wallet-strategy/strategies/Ledger/Base.ts index 163e10da0..31dd69837 100644 --- a/packages/wallet-ts/src/strategies/wallet-strategy/strategies/Ledger/Base.ts +++ b/packages/wallet-ts/src/strategies/wallet-strategy/strategies/Ledger/Base.ts @@ -1,40 +1,40 @@ /* eslint-disable class-methods-use-this */ -import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types' -import { bufferToHex, addHexPrefix } from 'ethereumjs-util' -import { Common, Chain, Hardfork } from '@ethereumjs/common' -import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' import { ErrorType, - GeneralException, LedgerException, - TransactionException, - UnspecifiedErrorCode, WalletException, + GeneralException, + UnspecifiedErrorCode, + TransactionException, } from '@injectivelabs/exceptions' import { DirectSignResponse } from '@cosmjs/proto-signing' +import { bufferToHex, addHexPrefix } from 'ethereumjs-util' +import { Common, Chain, Hardfork } from '@ethereumjs/common' +import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' +import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk' +import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types' import { TxGrpcApi, TxRaw, TxResponse, toUtf8 } from '@injectivelabs/sdk-ts' -import { TIP_IN_GWEI } from '../../../../utils/constants.js' +import { + LedgerWalletInfo, + SendTransactionOptions, + LedgerDerivationPathType, +} from '../../types.js' import { ConcreteWalletStrategy, EthereumWalletStrategyArgs, WalletStrategyEthereumOptions, } from '../../../types/index.js' -import { - LedgerDerivationPathType, - LedgerWalletInfo, - SendTransactionOptions, -} from '../../types.js' -import BaseConcreteStrategy from '../Base.js' import { DEFAULT_BASE_DERIVATION_PATH, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '../../constants.js' import LedgerHW from './hw/index.js' +import BaseConcreteStrategy from '../Base.js' import { domainHash, messageHash } from './utils.js' -import { WalletAction, WalletDeviceType } from '../../../../types/enums.js' +import { TIP_IN_GWEI } from '../../../../utils/constants.js' import { getKeyFromRpcUrl } from '../../../../utils/alchemy.js' -import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk' +import { WalletAction, WalletDeviceType } from '../../../../types/enums.js' const getNetworkFromChainId = (chainId: EthereumChainId): Chain => { if (chainId === EthereumChainId.Goerli) { diff --git a/packages/wallets/wallet-base/src/utils/wallet.ts b/packages/wallets/wallet-base/src/utils/wallet.ts index 3daff13cb..a10eae65f 100644 --- a/packages/wallets/wallet-base/src/utils/wallet.ts +++ b/packages/wallets/wallet-base/src/utils/wallet.ts @@ -1,6 +1,6 @@ import { Wallet } from './../types/enums.js' -export const isEthWallet = (wallet: Wallet): boolean => +export const isEvmWallet = (wallet: Wallet): boolean => [ Wallet.Magic, Wallet.Torus, @@ -17,7 +17,25 @@ export const isEthWallet = (wallet: Wallet): boolean => Wallet.CosmostationEth, ].includes(wallet) -export const isCosmosWallet = (wallet: Wallet): boolean => !isEthWallet(wallet) +export const isCosmosWallet = (wallet: Wallet): boolean => !isEvmWallet(wallet) + +export const isEvmBrowserWallet = (wallet: Wallet) => [ + Wallet.BitGet, + Wallet.Phantom, + Wallet.Metamask, + Wallet.OkxWallet, + Wallet.TrustWallet, +].includes(wallet) + + +export const isCosmosBrowserWallet = (wallet: Wallet): boolean => + [ + Wallet.Leap, + Wallet.Ninji, + Wallet.Keplr, + Wallet.OWallet, + Wallet.Cosmostation, + ].includes(wallet) export const isEip712V2OnlyWallet = (wallet: Wallet): boolean => [ @@ -29,11 +47,3 @@ export const isEip712V2OnlyWallet = (wallet: Wallet): boolean => export const isCosmosAminoOnlyWallet = (wallet: Wallet): boolean => [Wallet.LedgerCosmos].includes(wallet) - -export const COSMOS_WALLETS = [ - Wallet.Keplr, - Wallet.Leap, - Wallet.Ninji, - Wallet.Cosmostation, - Wallet.OWallet, -] diff --git a/packages/wallets/wallet-core/package.json b/packages/wallets/wallet-core/package.json index ec49f106b..74b9da43b 100644 --- a/packages/wallets/wallet-core/package.json +++ b/packages/wallets/wallet-core/package.json @@ -60,7 +60,7 @@ "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^0.0.6", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", "eip1193-provider": "^1.0.1" }, "devDependencies": { diff --git a/packages/wallets/wallet-core/src/strategy/BaseWalletStrategy.ts b/packages/wallets/wallet-core/src/strategy/BaseWalletStrategy.ts index e984ebe53..a09c11e4b 100644 --- a/packages/wallets/wallet-core/src/strategy/BaseWalletStrategy.ts +++ b/packages/wallets/wallet-core/src/strategy/BaseWalletStrategy.ts @@ -12,7 +12,7 @@ import { import { GeneralException, WalletException } from '@injectivelabs/exceptions' import { Wallet, - isEthWallet, + isEvmWallet, isCosmosWallet, WalletDeviceType, ConcreteStrategiesArg, @@ -151,7 +151,7 @@ export default class BaseWalletStrategy implements WalletStrategyInterface { signDoc: StdSignDoc address: string }): Promise { - if (isEthWallet(this.wallet)) { + if (isEvmWallet(this.wallet)) { throw new WalletException( new Error(`You can't sign Cosmos Transaction using ${this.wallet}`), ) @@ -166,7 +166,7 @@ export default class BaseWalletStrategy implements WalletStrategyInterface { chainId: string address: string }): Promise { - if (isEthWallet(this.wallet)) { + if (isEvmWallet(this.wallet)) { throw new WalletException( new Error(`You can't sign Cosmos Transaction using ${this.wallet}`), ) @@ -207,7 +207,7 @@ export default class BaseWalletStrategy implements WalletStrategyInterface { } public getCosmosWallet(chainId: ChainId): CosmosWalletAbstraction { - if ([Wallet.Keplr, Wallet.Leap].includes(this.getWallet())) { + if (![Wallet.Keplr, Wallet.Leap].includes(this.getWallet())) { throw new WalletException( new Error(`You can't use this method outside of Keplr/Leap wallet`), ) diff --git a/packages/wallets/wallet-cosmos/src/cosmos.d.ts b/packages/wallets/wallet-cosmos/src/cosmos.d.ts index 7b1c30ed2..c50b57cc3 100644 --- a/packages/wallets/wallet-cosmos/src/cosmos.d.ts +++ b/packages/wallets/wallet-cosmos/src/cosmos.d.ts @@ -6,5 +6,6 @@ declare global { leap: KeplrWindow['keplr'] keplr: KeplrWindow['keplr'] ninji: KeplrWindow['ninji'] + owallet?: KeplrWindow['owallet'] } } diff --git a/packages/wallets/wallet-cosmos/src/data/index.ts b/packages/wallets/wallet-cosmos/src/data/index.ts new file mode 100644 index 000000000..dd6b3e260 --- /dev/null +++ b/packages/wallets/wallet-cosmos/src/data/index.ts @@ -0,0 +1,8 @@ +import { Wallet } from '@injectivelabs/wallet-base' + +export const cosmosWallets = [ + Wallet.Leap, + Wallet.Ninji, + Wallet.Keplr, + Wallet.OWallet, +] diff --git a/packages/wallets/wallet-cosmos/src/index.ts b/packages/wallets/wallet-cosmos/src/index.ts index dbcbb3896..2aba985bd 100644 --- a/packages/wallets/wallet-cosmos/src/index.ts +++ b/packages/wallets/wallet-cosmos/src/index.ts @@ -1,2 +1,3 @@ export { CosmosWallet } from './wallet.js' export { CosmosWalletStrategy } from './strategy/strategy.js' +export * from './utils/index.js' diff --git a/packages/wallets/wallet-cosmos/src/strategy/strategy.ts b/packages/wallets/wallet-cosmos/src/strategy/strategy.ts index 88fb13c22..84b968597 100644 --- a/packages/wallets/wallet-cosmos/src/strategy/strategy.ts +++ b/packages/wallets/wallet-cosmos/src/strategy/strategy.ts @@ -31,6 +31,7 @@ import { SendTransactionOptions, createCosmosSignDocFromSignDoc, } from '@injectivelabs/wallet-base' +import { capitalize } from '@injectivelabs/utils' import { CosmosWallet } from './../wallet.js' const cosmosWallets = [Wallet.Leap, Wallet.Ninji, Wallet.Keplr, Wallet.OWallet] @@ -52,13 +53,18 @@ export class CosmosWalletStrategy if (!cosmosWallets.includes(args.wallet)) { throw new CosmosWalletException( - new Error(`Cosmos Wallet for ${args.wallet} is not supported.`), + new Error( + `Cosmos Wallet for ${capitalize(args.wallet)} is not supported.`, + ), ) } this.wallet = args.wallet this.chainId = args.chainId || CosmosChainId.Injective - this.cosmosWallet = new CosmosWallet(args.chainId, args.wallet) + this.cosmosWallet = new CosmosWallet({ + wallet: args.wallet, + chainId: args.chainId, + }) } async getWalletDeviceType(): Promise { @@ -137,7 +143,9 @@ export class CosmosWalletStrategy throw new CosmosWalletException( new Error( - `sendEthereumTransaction is not supported. ${wallet} only supports sending cosmos transactions`, + `sendEthereumTransaction is not supported. ${capitalize( + wallet, + )} only supports sending cosmos transactions`, ), { code: UnspecifiedErrorCode, @@ -252,7 +260,7 @@ export class CosmosWalletStrategy const { wallet } = this throw new CosmosWalletException( - new Error(`getEthereumChainId is not supported on ${wallet}`), + new Error(`getEthereumChainId is not supported on ${capitalize(wallet)}`), { code: UnspecifiedErrorCode, context: WalletAction.GetChainId, @@ -264,7 +272,11 @@ export class CosmosWalletStrategy const { wallet } = this throw new CosmosWalletException( - new Error(`getEthereumTransactionReceipt is not supported on ${wallet}`), + new Error( + `getEthereumTransactionReceipt is not supported on ${capitalize( + wallet, + )}`, + ), { code: UnspecifiedErrorCode, context: WalletAction.GetEthereumTransactionReceipt, @@ -310,7 +322,7 @@ export class CosmosWalletStrategy public getCosmosWallet(chainId: ChainId): CosmosWallet { const { wallet, cosmosWallet } = this - return !cosmosWallet ? new CosmosWallet(chainId, wallet) : cosmosWallet + return !cosmosWallet ? new CosmosWallet({ chainId, wallet }) : cosmosWallet } private getCurrentCosmosWallet(): CosmosWallet { @@ -318,7 +330,7 @@ export class CosmosWalletStrategy if (!cosmosWallet) { throw new CosmosWalletException( - new Error(`Please install the ${wallet} wallet extension`), + new Error(`Please install the ${capitalize(wallet)} wallet extension`), { code: UnspecifiedErrorCode, type: ErrorType.WalletNotInstalledError, diff --git a/packages/wallets/wallet-cosmos/src/utils/index.ts b/packages/wallets/wallet-cosmos/src/utils/index.ts new file mode 100644 index 000000000..9b06c3718 --- /dev/null +++ b/packages/wallets/wallet-cosmos/src/utils/index.ts @@ -0,0 +1,64 @@ +import type { Keplr as CosmosBrowserWallet } from '@keplr-wallet/types' +import { ChainId } from '@injectivelabs/ts-types' +import { PublicKey } from '@injectivelabs/sdk-ts' +import { Wallet } from '@injectivelabs/wallet-base' +import { capitalize } from '@injectivelabs/utils' +import { CosmosWalletException } from '@injectivelabs/exceptions' +import { CosmosWallet } from './../wallet.js' +import { cosmosWallets } from './../data/index.js' + +export const isCosmosWalletInstalled = (wallet: Wallet) => { + const $window = (typeof window !== 'undefined' ? window : {}) as Window & { + leap?: CosmosBrowserWallet + keplr?: CosmosBrowserWallet + ninji?: CosmosBrowserWallet + oWallet?: CosmosBrowserWallet + } + + switch (wallet) { + case Wallet.Keplr: + return $window.keplr !== undefined + case Wallet.Ninji: + return $window.ninji !== undefined + case Wallet.Leap: + return $window.leap !== undefined + case Wallet.OWallet: + return $window.oWallet !== undefined + default: + return false + } +} + +export const confirmCosmosAddress = async ({ + wallet, + chainId, + injectiveAddress, +}: { + wallet: Wallet + chainId: ChainId + injectiveAddress: string +}) => { + if (!cosmosWallets.includes(wallet)) { + throw new CosmosWalletException( + new Error(`Cosmos Wallet for ${capitalize(wallet)} is not supported.`), + ) + } + + const cosmosWallet = new CosmosWallet({ chainId, wallet }) + const key = await cosmosWallet.getKey() + const publicKey = PublicKey.fromBase64( + Buffer.from(key.pubKey).toString('base64'), + ) + + const { address: derivedAddress } = publicKey.toAddress() + + if (derivedAddress !== injectiveAddress) { + throw new CosmosWalletException( + new Error( + `Connected ${capitalize( + wallet, + )} address is wrong. Please update Injective on ${capitalize(wallet)}.`, + ), + ) + } +} diff --git a/packages/wallets/wallet-cosmos/src/wallet.ts b/packages/wallets/wallet-cosmos/src/wallet.ts index 1929fec4e..58e26dff3 100644 --- a/packages/wallets/wallet-cosmos/src/wallet.ts +++ b/packages/wallets/wallet-cosmos/src/wallet.ts @@ -18,9 +18,10 @@ import { CosmosWalletException, WalletErrorActionModule, } from '@injectivelabs/exceptions' +import { capitalize } from '@injectivelabs/utils' import { BroadcastMode } from '@cosmjs/launchpad' -import { Wallet } from '@injectivelabs/wallet-base' import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts' +import { Wallet } from '@injectivelabs/wallet-base' import { SigningStargateClient, StdFee } from '@cosmjs/stargate' import type { EncodeObject, OfflineDirectSigner } from '@cosmjs/proto-signing' @@ -35,10 +36,13 @@ export class CosmosWallet { public wallet: Wallet private chainId: CosmosChainId | TestnetCosmosChainId | ChainId - constructor( - chainId: CosmosChainId | TestnetCosmosChainId | ChainId, - wallet: Wallet, - ) { + constructor({ + wallet, + chainId, + }: { + wallet: Wallet + chainId: CosmosChainId | TestnetCosmosChainId | ChainId + }) { this.wallet = wallet this.chainId = chainId } @@ -46,7 +50,7 @@ export class CosmosWallet { public async isChainIdSupported(chainId: CosmosChainId): Promise { const { wallet } = this - return new CosmosWallet(chainId, wallet).checkChainIdSupport() + return new CosmosWallet({ chainId, wallet }).checkChainIdSupport() } public async getCosmosWallet() { @@ -75,7 +79,7 @@ export class CosmosWallet { throw new CosmosWalletException( new Error( - `${wallet} may not support ${ + `${capitalize(wallet)} may not support ${ chainName[0] || chainId } network. Please check if the chain can be added.`, ), @@ -136,7 +140,9 @@ export class CosmosWallet { if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) { throw new CosmosWalletException( - new Error(`getOfflineAminoSigner is not support on ${wallet}`), + new Error( + `getOfflineAminoSigner is not support on ${capitalize(wallet)}`, + ), ) } @@ -243,7 +249,9 @@ export class CosmosWallet { if (![Wallet.Keplr, Wallet.OWallet].includes(wallet)) { throw new CosmosWalletException( new Error( - `signAndBroadcastAminoUsingCosmjs is not support on ${wallet}`, + `signAndBroadcastAminoUsingCosmjs is not support on ${capitalize( + wallet, + )}`, ), ) } @@ -280,7 +288,7 @@ export class CosmosWallet { if (wallet !== Wallet.Keplr) { throw new CosmosWalletException( - new Error(`signArbitrary is not supported on ${wallet}`), + new Error(`signArbitrary is not supported on ${capitalize(wallet)}`), ) } @@ -332,7 +340,7 @@ export class CosmosWallet { } catch (e) { throw new CosmosWalletException( new Error( - `${wallet} doesn't support ${ + `${capitalize(wallet)} doesn't support ${ chainName[0] || chainId } network. Please use another Cosmos wallet`, ), @@ -345,7 +353,7 @@ export class CosmosWallet { if (!$window) { throw new CosmosWalletException( - new Error(`Please install ${wallet} extension`), + new Error(`Please install ${capitalize(wallet)} extension`), { code: UnspecifiedErrorCode, type: ErrorType.WalletNotInstalledError, @@ -374,7 +382,7 @@ export class CosmosWallet { if (!cosmos) { throw new CosmosWalletException( - new Error(`Please install ${wallet} extension`), + new Error(`Please install ${capitalize(wallet)} extension`), { code: UnspecifiedErrorCode, type: ErrorType.WalletNotInstalledError, @@ -390,9 +398,9 @@ export class CosmosWallet { const { wallet } = this const cosmosWallet = await this.getCosmosWallet() - if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) { + if (![Wallet.Keplr, Wallet.OWallet].includes(wallet)) { throw new CosmosWalletException( - new Error(`disableGasCheck is not support on ${wallet}`), + new Error(`disableGasCheck is not support on ${capitalize(wallet)}`), ) } @@ -412,7 +420,7 @@ export class CosmosWallet { if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) { throw new CosmosWalletException( - new Error(`enableGasCheck is not support on ${wallet}`), + new Error(`enableGasCheck is not support on ${capitalize(wallet)}`), ) } diff --git a/packages/wallets/wallet-cosmostation/src/index.ts b/packages/wallets/wallet-cosmostation/src/index.ts index 5f47151f4..013525b61 100644 --- a/packages/wallets/wallet-cosmostation/src/index.ts +++ b/packages/wallets/wallet-cosmostation/src/index.ts @@ -1,2 +1,3 @@ export { CosmostationWallet } from './wallet.js' export { Cosmostation as CosmostationWalletStrategy } from './strategy/strategy.js' +export * from './utils/index.js' diff --git a/packages/wallets/wallet-cosmostation/src/utils/index.ts b/packages/wallets/wallet-cosmostation/src/utils/index.ts new file mode 100644 index 000000000..e5c72a5e6 --- /dev/null +++ b/packages/wallets/wallet-cosmostation/src/utils/index.ts @@ -0,0 +1,9 @@ +import { Cosmos } from '@cosmostation/extension-client' + +export const isCosmosStationWalletInstalled = () => { + const $window = (typeof window !== 'undefined' ? window : {}) as Window & { + cosmostation?: Cosmos + } + + return $window.cosmostation !== undefined +} diff --git a/packages/wallets/wallet-evm/package.json b/packages/wallets/wallet-evm/package.json index 78d0a0387..a22d99148 100644 --- a/packages/wallets/wallet-evm/package.json +++ b/packages/wallets/wallet-evm/package.json @@ -60,7 +60,7 @@ "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^0.0.6", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", "ethers": "^6.5.1", "long": "^5.2.1", "shx": "^0.3.3" diff --git a/packages/wallets/wallet-evm/src/index.ts b/packages/wallets/wallet-evm/src/index.ts index 7be5a8d63..d5907c594 100644 --- a/packages/wallets/wallet-evm/src/index.ts +++ b/packages/wallets/wallet-evm/src/index.ts @@ -1,3 +1,4 @@ export { EvmWallet as EvmWalletStrategy } from './strategy/strategy.js' + export * from './strategy/utils/index.js' export * from './utils/index.js' diff --git a/packages/wallets/wallet-evm/src/strategy/strategy.ts b/packages/wallets/wallet-evm/src/strategy/strategy.ts index 3af529d7d..bfb786f1a 100644 --- a/packages/wallets/wallet-evm/src/strategy/strategy.ts +++ b/packages/wallets/wallet-evm/src/strategy/strategy.ts @@ -1,4 +1,13 @@ /* eslint-disable class-methods-use-this */ +import { isEvmBrowserWallet } from '@injectivelabs/wallet-base' +import { + TxRaw, + toUtf8, + TxGrpcApi, + TxResponse, + DirectSignResponse, + AminoSignResponse, +} from '@injectivelabs/sdk-ts' import { ErrorType, ErrorContext, @@ -24,16 +33,8 @@ import { ConcreteWalletStrategyArgs, ConcreteEthereumWalletStrategyArgs, } from '@injectivelabs/wallet-base' -import { sleep } from '@injectivelabs/utils' +import { sleep, capitalize } from '@injectivelabs/utils' import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types' -import { - TxRaw, - toUtf8, - TxGrpcApi, - TxResponse, - DirectSignResponse, - AminoSignResponse, -} from '@injectivelabs/sdk-ts' import { getBitGetProvider, getPhantomProvider, @@ -42,14 +43,6 @@ import { getTrustWalletProvider, } from './utils/index.js' -const evmWallets = [ - Wallet.BitGet, - Wallet.Phantom, - Wallet.Metamask, - Wallet.OkxWallet, - Wallet.TrustWallet, -] - export class EvmWallet extends BaseConcreteStrategy implements ConcreteWalletStrategy @@ -63,9 +56,11 @@ export class EvmWallet ) { super(args) - if (!evmWallets.includes(args.wallet)) { + if (!isEvmBrowserWallet(args.wallet)) { throw new WalletException( - new Error(`Evm Wallet for ${args.wallet} is not supported.`), + new Error( + `Evm Wallet for ${capitalize(args.wallet)} is not supported.`, + ), ) } diff --git a/packages/wallets/wallet-evm/src/utils/index.ts b/packages/wallets/wallet-evm/src/utils/index.ts index 01fe03894..b8bd831a8 100644 --- a/packages/wallets/wallet-evm/src/utils/index.ts +++ b/packages/wallets/wallet-evm/src/utils/index.ts @@ -1,31 +1,82 @@ -import { ethers } from 'ethers' -import { WalletException } from '@injectivelabs/exceptions' +import { + Wallet, + isEvmBrowserWallet, + BrowserEip1993Provider, +} from '@injectivelabs/wallet-base' +import { capitalize } from '@injectivelabs/utils' import { EthereumChainId } from '@injectivelabs/ts-types' +import { WalletException } from '@injectivelabs/exceptions' +import { getOkxWalletProvider } from '../strategy/utils/Okx.js' +import { getBitGetProvider } from '../strategy/utils/bitget.js' +import { getPhantomProvider } from '../strategy/utils/phantom.js' import { getMetamaskProvider } from '../strategy/utils/metamask.js' -import { BrowserEip1993Provider } from '@injectivelabs/wallet-base' +import { getTrustWalletProvider } from '../strategy/utils/trustWallet.js' + +export const getEvmProvider = async ( + wallet: Wallet, +): Promise => { + if (!isEvmBrowserWallet(wallet)) { + throw new WalletException( + new Error(`Evm Wallet for ${capitalize(wallet)} is not supported.`), + ) + } -export const getEthersProviderFromMetamask = async () => { try { - const provider = (await getMetamaskProvider()) as BrowserEip1993Provider + let provider + + if (wallet === Wallet.Metamask) { + provider = (await getMetamaskProvider()) as BrowserEip1993Provider + } + + if (wallet === Wallet.BitGet) { + provider = (await getBitGetProvider()) as BrowserEip1993Provider + } + + if (wallet === Wallet.Phantom) { + provider = (await getPhantomProvider()) as BrowserEip1993Provider + } + + if (wallet === Wallet.TrustWallet) { + provider = (await getTrustWalletProvider()) as BrowserEip1993Provider + } + + if (wallet === Wallet.OkxWallet) { + provider = (await getOkxWalletProvider()) as BrowserEip1993Provider + } if (!provider) { - throw new WalletException(new Error('Please install Metamask Extension')) + throw new WalletException( + new Error(`Please install ${capitalize(wallet)} Extension`), + ) } - return new ethers.BrowserProvider(provider, 'any') + return provider } catch (e) { - throw new WalletException(new Error('Please install Metamask Extension')) + throw new WalletException( + new Error(`Please install ${capitalize(wallet)} Extension`), + ) } } -export const updateMetamaskNetwork = async (chainId: EthereumChainId) => { - try { - const provider = (await getMetamaskProvider()) as BrowserEip1993Provider +export const updateEvmNetwork = async ( + wallet: Wallet, + chainId: EthereumChainId, +) => { + if (!isEvmBrowserWallet(wallet)) { + throw new WalletException( + new Error(`Evm Wallet for ${capitalize(wallet)} is not supported.`), + ) + } - if (!provider) { - throw new WalletException(new Error('Please install Metamask Extension')) - } + const provider = (await getEvmProvider(wallet)) as BrowserEip1993Provider + if (!provider) { + throw new WalletException( + new Error(`Please install ${capitalize(wallet)} Extension`), + ) + } + + try { const chainIdToHex = chainId.toString(16) return await Promise.race([ @@ -42,6 +93,8 @@ export const updateMetamaskNetwork = async (chainId: EthereumChainId) => { ), ]) } catch (e) { - throw new WalletException(new Error('Please update your Metamask network')) + throw new WalletException( + new Error(`Please update your ${capitalize(wallet)} network`), + ) } } diff --git a/packages/wallets/wallet-private-key/src/strategy/strategy.ts b/packages/wallets/wallet-private-key/src/strategy/strategy.ts index bf1b5b79c..993ce9210 100644 --- a/packages/wallets/wallet-private-key/src/strategy/strategy.ts +++ b/packages/wallets/wallet-private-key/src/strategy/strategy.ts @@ -204,7 +204,7 @@ export class PrivateKeyWallet try { const signature = await pk.signHashed(Buffer.from(toUtf8(data), 'utf-8')) - return `0x${Buffer.from(signature).toString('base64')}` + return signature } catch (e: unknown) { throw new MetamaskException(new Error((e as any).message), { code: UnspecifiedErrorCode, diff --git a/packages/wallets/wallet-strategy/src/strategy/WalletStrategy.ts b/packages/wallets/wallet-strategy/src/strategy/WalletStrategy.ts deleted file mode 100644 index 013e6bbbb..000000000 --- a/packages/wallets/wallet-strategy/src/strategy/WalletStrategy.ts +++ /dev/null @@ -1,180 +0,0 @@ -import { - Wallet, - isEthWallet, - MagicMetadata, - ConcreteStrategiesArg, - ConcreteWalletStrategy, - WalletStrategyArguments, - ConcreteWalletStrategyOptions, - WalletStrategyEthereumOptions, - ConcreteEthereumWalletStrategyArgs, -} from '@injectivelabs/wallet-base' -import { - LedgerLiveStrategy, - LedgerLegacyStrategy, -} from '@injectivelabs/wallet-ledger' -import { MagicStrategy } from '@injectivelabs/wallet-magic' -import { EvmWalletStrategy } from '@injectivelabs/wallet-evm' -import { BaseWalletStrategy } from '@injectivelabs/wallet-core' -import { CosmosWalletStrategy } from '@injectivelabs/wallet-cosmos' -import { TrezorWalletStrategy } from '@injectivelabs/wallet-trezor' -import { WalletConnectStrategy } from '@injectivelabs/wallet-wallet-connect' -import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key' -import { CosmostationWalletStrategy } from '@injectivelabs/wallet-cosmostation' - -const ethereumWalletsDisabled = (args: WalletStrategyArguments) => { - const { ethereumOptions } = args - - if (!ethereumOptions) { - return true - } - - const { ethereumChainId } = ethereumOptions - - if (!ethereumChainId) { - return true - } - - return false -} - -const createStrategy = ({ - args, - wallet, -}: { - args: WalletStrategyArguments - wallet: Wallet -}): ConcreteWalletStrategy | undefined => { - /** - * If we only want to use Cosmos Native Wallets - * We are not creating strategies for Ethereum Native Wallets - */ - if (isEthWallet(wallet) && ethereumWalletsDisabled(args)) { - return undefined - } - - const ethWalletArgs = { - chainId: args.chainId, - ethereumOptions: args.ethereumOptions as WalletStrategyEthereumOptions, - } as ConcreteEthereumWalletStrategyArgs - - switch (wallet) { - case Wallet.Metamask: - return new EvmWalletStrategy({ - ...ethWalletArgs, - wallet: Wallet.Metamask, - }) - case Wallet.Ledger: - return new LedgerLiveStrategy(ethWalletArgs) - case Wallet.LedgerLegacy: - return new LedgerLegacyStrategy(ethWalletArgs) - case Wallet.TrustWallet: - return new EvmWalletStrategy({ - ...ethWalletArgs, - wallet: Wallet.TrustWallet, - }) - case Wallet.Trezor: - return new TrezorWalletStrategy(ethWalletArgs) - case Wallet.Phantom: - return new EvmWalletStrategy({ - ...ethWalletArgs, - wallet: Wallet.Phantom, - }) - case Wallet.OkxWallet: - return new EvmWalletStrategy({ - ...ethWalletArgs, - wallet: Wallet.OkxWallet, - }) - case Wallet.BitGet: - return new EvmWalletStrategy({ - ...ethWalletArgs, - wallet: Wallet.BitGet, - }) - case Wallet.WalletConnect: - return new WalletConnectStrategy({ - ...ethWalletArgs, - metadata: args.options?.metadata, - }) - case Wallet.PrivateKey: - return new PrivateKeyWalletStrategy({ - ...ethWalletArgs, - privateKey: args.options?.privateKey, - }) - case Wallet.Keplr: - return new CosmosWalletStrategy({ ...args, wallet: Wallet.Keplr }) - case Wallet.Cosmostation: - return new CosmostationWalletStrategy({ ...args }) - case Wallet.Leap: - return new CosmosWalletStrategy({ ...args, wallet: Wallet.Leap }) - case Wallet.Ninji: - return new CosmosWalletStrategy({ ...args, wallet: Wallet.Ninji }) - case Wallet.OWallet: - return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet }) - case Wallet.Magic: - if ( - !args.options?.metadata?.magic || - !(args.options?.metadata.magic as MagicMetadata)?.apiKey || - !(args.options?.metadata.magic as MagicMetadata)?.rpcEndpoint - ) { - return undefined - } - - return new MagicStrategy({ - ...args, - metadata: args.options.metadata.magic as MagicMetadata, - }) - default: - return undefined - } -} - -const createAllStrategies = ( - args: WalletStrategyArguments, -): ConcreteStrategiesArg => { - return Object.values(Wallet).reduce( - (strategies, wallet) => ({ - ...strategies, - [wallet]: createStrategy({ args, wallet: wallet as Wallet }), - }), - {} as ConcreteStrategiesArg, - ) -} - -export class WalletStrategy extends BaseWalletStrategy { - constructor(args: WalletStrategyArguments) { - const strategies = createAllStrategies(args) - - super({ - ...args, - strategies, - }) - } - - /** - * Case 1: Private Key is set dynamically - * If we have a dynamically set private key, - * we are creating a new PrivateKey strategy - * with the specified private key - * - * Case 2: Wallet Connect Metadata set dynamically - */ - public setOptions(options?: ConcreteWalletStrategyOptions) { - if (options?.privateKey) { - this.strategies[Wallet.PrivateKey] = createStrategy({ - args: { ...this.args, options: { privateKey: options.privateKey } }, - wallet: Wallet.PrivateKey, - }) - } - - if (options?.metadata) { - this.strategies[Wallet.WalletConnect] = createStrategy({ - args: { ...this.args, options: { metadata: options.metadata } }, - wallet: Wallet.WalletConnect, - }) - } - } -} - -export const createStrategyFactory = (args: WalletStrategyArguments) => { - return new WalletStrategy(args) -} diff --git a/packages/wallets/wallet-strategy/src/strategy/index.ts b/packages/wallets/wallet-strategy/src/strategy/index.ts index aa1136ab5..6b44fa8ab 100644 --- a/packages/wallets/wallet-strategy/src/strategy/index.ts +++ b/packages/wallets/wallet-strategy/src/strategy/index.ts @@ -1 +1,180 @@ -export * from './WalletStrategy.js' +import { + Wallet, + isEvmWallet, + MagicMetadata, + ConcreteStrategiesArg, + ConcreteWalletStrategy, + WalletStrategyArguments, + ConcreteWalletStrategyOptions, + WalletStrategyEthereumOptions, + ConcreteEthereumWalletStrategyArgs, +} from '@injectivelabs/wallet-base' +import { + LedgerLiveStrategy, + LedgerLegacyStrategy, +} from '@injectivelabs/wallet-ledger' +import { MagicStrategy } from '@injectivelabs/wallet-magic' +import { EvmWalletStrategy } from '@injectivelabs/wallet-evm' +import { BaseWalletStrategy } from '@injectivelabs/wallet-core' +import { CosmosWalletStrategy } from '@injectivelabs/wallet-cosmos' +import { TrezorWalletStrategy } from '@injectivelabs/wallet-trezor' +import { WalletConnectStrategy } from '@injectivelabs/wallet-wallet-connect' +import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key' +import { CosmostationWalletStrategy } from '@injectivelabs/wallet-cosmostation' + +const ethereumWalletsDisabled = (args: WalletStrategyArguments) => { + const { ethereumOptions } = args + + if (!ethereumOptions) { + return true + } + + const { ethereumChainId } = ethereumOptions + + if (!ethereumChainId) { + return true + } + + return false +} + +const createStrategy = ({ + args, + wallet, +}: { + args: WalletStrategyArguments + wallet: Wallet +}): ConcreteWalletStrategy | undefined => { + /** + * If we only want to use Cosmos Native Wallets + * We are not creating strategies for Ethereum Native Wallets + */ + if (isEvmWallet(wallet) && ethereumWalletsDisabled(args)) { + return undefined + } + + const ethWalletArgs = { + chainId: args.chainId, + ethereumOptions: args.ethereumOptions as WalletStrategyEthereumOptions, + } as ConcreteEthereumWalletStrategyArgs + + switch (wallet) { + case Wallet.Metamask: + return new EvmWalletStrategy({ + ...ethWalletArgs, + wallet: Wallet.Metamask, + }) + case Wallet.Ledger: + return new LedgerLiveStrategy(ethWalletArgs) + case Wallet.LedgerLegacy: + return new LedgerLegacyStrategy(ethWalletArgs) + case Wallet.TrustWallet: + return new EvmWalletStrategy({ + ...ethWalletArgs, + wallet: Wallet.TrustWallet, + }) + case Wallet.Trezor: + return new TrezorWalletStrategy(ethWalletArgs) + case Wallet.Phantom: + return new EvmWalletStrategy({ + ...ethWalletArgs, + wallet: Wallet.Phantom, + }) + case Wallet.OkxWallet: + return new EvmWalletStrategy({ + ...ethWalletArgs, + wallet: Wallet.OkxWallet, + }) + case Wallet.BitGet: + return new EvmWalletStrategy({ + ...ethWalletArgs, + wallet: Wallet.BitGet, + }) + case Wallet.WalletConnect: + return new WalletConnectStrategy({ + ...ethWalletArgs, + metadata: args.options?.metadata, + }) + case Wallet.PrivateKey: + return new PrivateKeyWalletStrategy({ + ...ethWalletArgs, + privateKey: args.options?.privateKey, + }) + case Wallet.Keplr: + return new CosmosWalletStrategy({ ...args, wallet: Wallet.Keplr }) + case Wallet.Cosmostation: + return new CosmostationWalletStrategy({ ...args }) + case Wallet.Leap: + return new CosmosWalletStrategy({ ...args, wallet: Wallet.Leap }) + case Wallet.Ninji: + return new CosmosWalletStrategy({ ...args, wallet: Wallet.Ninji }) + case Wallet.OWallet: + return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet }) + case Wallet.Magic: + if ( + !args.options?.metadata?.magic || + !(args.options?.metadata.magic as MagicMetadata)?.apiKey || + !(args.options?.metadata.magic as MagicMetadata)?.rpcEndpoint + ) { + return undefined + } + + return new MagicStrategy({ + ...args, + metadata: args.options.metadata.magic as MagicMetadata, + }) + default: + return undefined + } +} + +const createAllStrategies = ( + args: WalletStrategyArguments, +): ConcreteStrategiesArg => { + return Object.values(Wallet).reduce( + (strategies, wallet) => ({ + ...strategies, + [wallet]: createStrategy({ args, wallet: wallet as Wallet }), + }), + {} as ConcreteStrategiesArg, + ) +} + +export class WalletStrategy extends BaseWalletStrategy { + constructor(args: WalletStrategyArguments) { + const strategies = createAllStrategies(args) + + super({ + ...args, + strategies, + }) + } + + /** + * Case 1: Private Key is set dynamically + * If we have a dynamically set private key, + * we are creating a new PrivateKey strategy + * with the specified private key + * + * Case 2: Wallet Connect Metadata set dynamically + */ + public setOptions(options?: ConcreteWalletStrategyOptions) { + if (options?.privateKey) { + this.strategies[Wallet.PrivateKey] = createStrategy({ + args: { ...this.args, options: { privateKey: options.privateKey } }, + wallet: Wallet.PrivateKey, + }) + } + + if (options?.metadata) { + this.strategies[Wallet.WalletConnect] = createStrategy({ + args: { ...this.args, options: { metadata: options.metadata } }, + wallet: Wallet.WalletConnect, + }) + } + } +} + +export const createStrategyFactory = (args: WalletStrategyArguments) => { + return new WalletStrategy(args) +} diff --git a/yarn.lock b/yarn.lock index 1acd239a8..605413172 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2210,16 +2210,6 @@ dependencies: browser-headers "^0.4.1" -"@injectivelabs/indexer-proto-ts@1.13.1": - version "1.13.1" - resolved "https://registry.npmjs.org/@injectivelabs/indexer-proto-ts/-/indexer-proto-ts-1.13.1.tgz#94de25619e1725d393c2e447298374466540e763" - integrity sha512-w5C2qREyNZyc7bvGUvxzl5JetUkChFDTzZqW55qox+Iy6jiCkNILPTiArlHMlv/i04ymJ3B70Ftsr1j7V4lZrA== - dependencies: - "@injectivelabs/grpc-web" "^0.0.1" - google-protobuf "^3.14.0" - protobufjs "^7.0.0" - rxjs "^7.4.0" - "@injectivelabs/indexer-proto-ts@1.13.3": version "1.13.3" resolved "https://registry.yarnpkg.com/@injectivelabs/indexer-proto-ts/-/indexer-proto-ts-1.13.3.tgz#9f1963a8bc87bd4d6f88262fb4a4552b2e6fa79e" @@ -2250,67 +2240,6 @@ protobufjs "^7.0.0" rxjs "^7.4.0" -"@injectivelabs/sdk-ts@^1.14.19": - version "1.14.32" - resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ts/-/sdk-ts-1.14.32.tgz#560bc07a717d14bac81ee4f5ef17f9ac42abbd67" - integrity sha512-l4V5TK4QnTS8kgv4Qnmmi4rZo+2yF9y4S6lhH6eoyRuPb/xXODUzkyQDIHwbd1Qf92G31qSdL76Koe13v/SBIQ== - dependencies: - "@apollo/client" "^3.11.10" - "@cosmjs/amino" "^0.32.3" - "@cosmjs/proto-signing" "^0.32.3" - "@cosmjs/stargate" "^0.32.3" - "@ethersproject/bytes" "^5.7.0" - "@injectivelabs/core-proto-ts" "1.13.4" - "@injectivelabs/exceptions" "^1.14.32" - "@injectivelabs/grpc-web" "^0.0.1" - "@injectivelabs/grpc-web-node-http-transport" "^0.0.2" - "@injectivelabs/grpc-web-react-native-transport" "^0.0.2" - "@injectivelabs/indexer-proto-ts" "1.13.1" - "@injectivelabs/mito-proto-ts" "1.13.0" - "@injectivelabs/networks" "^1.14.32" - "@injectivelabs/olp-proto-ts" "1.13.1" - "@injectivelabs/test-utils" "^1.14.32" - "@injectivelabs/ts-types" "^1.14.32" - "@injectivelabs/utils" "^1.14.32" - "@metamask/eth-sig-util" "^4.0.0" - "@noble/curves" "^1.4.0" - axios "^1.6.4" - bech32 "^2.0.0" - bip39 "^3.0.4" - cosmjs-types "^0.9.0" - ethereumjs-util "^7.1.4" - ethers "^6.5.1" - google-protobuf "^3.21.0" - graphql "^16.3.0" - http-status-codes "^2.2.0" - js-sha3 "^0.8.0" - jscrypto "^1.0.3" - keccak256 "^1.0.6" - secp256k1 "^4.0.3" - shx "^0.3.2" - snakecase-keys "^5.4.1" - -"@injectivelabs/wallet-base@^0.0.6": - version "0.0.6" - resolved "https://registry.yarnpkg.com/@injectivelabs/wallet-base/-/wallet-base-0.0.6.tgz#073ee305b901c939b1dd5807b0506105c8d3f84d" - integrity sha512-QfFCW7KGbTC6MSPZxTAwy4vqH855EHWtvEXi3l3cS2OWb8llt1XhOc2W0YiCywcgEWh/Sv7EQb00VfMQAGM58g== - dependencies: - "@ethereumjs/common" "^3.1.1" - "@ethereumjs/tx" "^4.1.1" - "@injectivelabs/exceptions" "^1.14.19" - "@injectivelabs/networks" "^1.14.19" - "@injectivelabs/sdk-ts" "^1.14.19" - "@injectivelabs/ts-types" "^1.14.19" - "@injectivelabs/utils" "^1.14.19" - alchemy-sdk "^3.4.7" - eip1193-provider "^1.0.1" - eth-sig-util "^3.0.1" - ethereumjs-util "^7.1.0" - ethers "^6.5.1" - hdkey "^2.0.1" - long "^5.2.1" - shx "^0.3.3" - "@ioredis/commands@^1.1.1": version "1.2.0" resolved "https://registry.npmjs.org/@ioredis/commands/-/commands-1.2.0.tgz#6d61b3097470af1fdbbe622795b8921d42018e11" @@ -12163,12 +12092,7 @@ libsodium-wrappers-sumo@^0.7.11: dependencies: libsodium-sumo "^0.7.13" -libsodium-wrappers@^0.7.6, "libsodium-wrappers@npm:@bangjelkoski/noop": - version "0.0.1" - resolved "https://registry.npmjs.org/@bangjelkoski/noop/-/noop-0.0.1.tgz#172235ce00dd4269258c420f01464f07eb9801ed" - integrity sha512-lQgYJJbok2Unu2vKh0TAtWxXo16kLXNrjqmfo0hQTAuE/tVvz5zVqMgGsj+gMkkWfsInEbUndG0nlyCwaFv8hQ== - -"libsodium@npm:@bangjelkoski/noop": +libsodium-wrappers@^0.7.6, "libsodium-wrappers@npm:@bangjelkoski/noop", "libsodium@npm:@bangjelkoski/noop": version "0.0.1" resolved "https://registry.npmjs.org/@bangjelkoski/noop/-/noop-0.0.1.tgz#172235ce00dd4269258c420f01464f07eb9801ed" integrity sha512-lQgYJJbok2Unu2vKh0TAtWxXo16kLXNrjqmfo0hQTAuE/tVvz5zVqMgGsj+gMkkWfsInEbUndG0nlyCwaFv8hQ==