From 17b92e252c5135f999dff9d937acc98249463977 Mon Sep 17 00:00:00 2001 From: danidomi Date: Wed, 27 Nov 2024 07:36:53 +0000 Subject: [PATCH 1/6] feat: bump v1.13.78-RC.1 --- proto/indexer/gen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/indexer/gen.sh b/proto/indexer/gen.sh index 80ed92464..24ac55cb9 100755 --- a/proto/indexer/gen.sh +++ b/proto/indexer/gen.sh @@ -3,7 +3,7 @@ BUILD_DIR=$ROOT_DIR/gen PROTO_DIR=$ROOT_DIR/proto TS_OUTPUT_DIR=$ROOT_DIR/proto-ts TS_STUB_DIR=$ROOT_DIR/stub -injective_indexer_branch=v1.13.76 +injective_indexer_branch=v1.13.78-RC.1 # remove old gen rm -rf $BUILD_DIR From 5e19e95e689fffeafa84cb21b49b5c86120ff737 Mon Sep 17 00:00:00 2001 From: ivan-angjelkoski Date: Thu, 28 Nov 2024 14:35:51 +0100 Subject: [PATCH 2/6] chore: trading strategies pnl --- packages/sdk-ts/package.json | 2 +- .../indexer/grpc/IndexerGrpcTradingApi.ts | 58 ++++++++++++++++--- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/packages/sdk-ts/package.json b/packages/sdk-ts/package.json index 46b4f266e..8a633dba6 100644 --- a/packages/sdk-ts/package.json +++ b/packages/sdk-ts/package.json @@ -126,7 +126,7 @@ "@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.2", + "@injectivelabs/indexer-proto-ts": "1.13.3", "@injectivelabs/mito-proto-ts": "1.13.0", "@injectivelabs/networks": "^1.14.32", "@injectivelabs/olp-proto-ts": "1.13.1", diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcTradingApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcTradingApi.ts index 138a11844..4a85ec79b 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcTradingApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcTradingApi.ts @@ -50,23 +50,37 @@ export class IndexerGrpcTradingApi extends BaseGrpcConsumer { } async fetchGridStrategies({ - accountAddress, - subaccountId, + skip, state, - marketId, limit, - skip, + withTvl, + endTime, + marketId, + startTime, marketType, strategyType, + subaccountId, + accountAddress, + withPerformance, + pendingExecution, + lastExecutedTime, + isTrailingStrategy, }: { - accountAddress?: string - subaccountId?: string + skip?: number state?: string - marketId?: string limit?: number - skip?: number + endTime?: number + withTvl?: boolean + marketId?: string + startTime?: number marketType?: MarketType + subaccountId?: string strategyType?: GridStrategyType[] + accountAddress?: string + withPerformance?: boolean + pendingExecution?: boolean + lastExecutedTime?: number + isTrailingStrategy?: boolean }) { const request = InjectiveTradingRpc.ListTradingStrategiesRequest.create() @@ -102,6 +116,34 @@ export class IndexerGrpcTradingApi extends BaseGrpcConsumer { request.marketId = marketId } + if (withTvl) { + request.withTvl = withTvl + } + + if (withPerformance) { + request.withPerformance = withPerformance + } + + if (isTrailingStrategy) { + request.isTrailingStrategy = isTrailingStrategy + } + + if (startTime) { + request.startTime = startTime.toString() + } + + if (endTime) { + request.endTime = endTime.toString() + } + + if (pendingExecution) { + request.pendingExecution = pendingExecution + } + + if (lastExecutedTime) { + request.lastExecutedTime = lastExecutedTime.toString() + } + try { const response = await this.retry( From 78456400085eb92651742a540991fa5d4b07f407 Mon Sep 17 00:00:00 2001 From: ivan-angjelkoski Date: Thu, 28 Nov 2024 14:37:55 +0100 Subject: [PATCH 3/6] chore: strategies pnl --- yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index 43a8a203e..1acd239a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2220,10 +2220,10 @@ protobufjs "^7.0.0" rxjs "^7.4.0" -"@injectivelabs/indexer-proto-ts@1.13.2": - version "1.13.2" - resolved "https://registry.yarnpkg.com/@injectivelabs/indexer-proto-ts/-/indexer-proto-ts-1.13.2.tgz#ad784602ea392b7a25410784cf90eed74895d07b" - integrity sha512-Sn6TiFslc1Lvxhljr5lJCymIRpAcsyfevAyQlGDbls0ZKHcZnl9oBHlFbCPA04dyNGcs9txU2odzBC/1hsYfwQ== +"@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" + integrity sha512-rLesVPCARl+OC82vj063/pUawYu0ISty/2+xg6ya4Lwk6PDbXmtRvw8wpNP6K+pAsBOKaSkRnO4ThP5qbX+E6A== dependencies: "@injectivelabs/grpc-web" "^0.0.1" google-protobuf "^3.14.0" From bddcbfc2f491af6a2dd6220bfad97f5402c90260 Mon Sep 17 00:00:00 2001 From: ivan-angjelkoski Date: Thu, 28 Nov 2024 13:43:01 +0000 Subject: [PATCH 4/6] chore: release - @injectivelabs/sdk-ts@1.14.33-beta.2 - @injectivelabs/wallet-ts@1.14.33-beta.2 - @injectivelabs/wallet-base@1.14.33-beta.2 - @injectivelabs/wallet-core@1.14.33-beta.2 - @injectivelabs/wallet-cosmos-strategy@1.14.33-beta.2 - @injectivelabs/wallet-cosmos@1.14.33-beta.2 - @injectivelabs/wallet-cosmostation@1.14.33-beta.2 - @injectivelabs/wallet-evm@1.14.33-beta.2 - @injectivelabs/wallet-ledger@1.14.33-beta.2 - @injectivelabs/wallet-magic@1.14.33-beta.2 - @injectivelabs/wallet-private-key@1.14.33-beta.2 - @injectivelabs/wallet-strategy@1.14.33-beta.2 - @injectivelabs/wallet-trezor@1.14.33-beta.2 - @injectivelabs/wallet-wallet-connect@1.14.33-beta.2 --- packages/sdk-ts/package.json | 2 +- packages/wallet-ts/package.json | 4 ++-- packages/wallets/wallet-base/package.json | 4 ++-- packages/wallets/wallet-core/package.json | 4 ++-- .../wallet-cosmos-strategy/package.json | 12 +++++----- packages/wallets/wallet-cosmos/package.json | 6 ++--- .../wallets/wallet-cosmostation/package.json | 6 ++--- packages/wallets/wallet-evm/package.json | 4 ++-- packages/wallets/wallet-ledger/package.json | 6 ++--- packages/wallets/wallet-magic/package.json | 6 ++--- .../wallets/wallet-private-key/package.json | 6 ++--- packages/wallets/wallet-strategy/package.json | 24 +++++++++---------- packages/wallets/wallet-trezor/package.json | 6 ++--- .../wallet-wallet-connect/package.json | 6 ++--- 14 files changed, 48 insertions(+), 48 deletions(-) diff --git a/packages/sdk-ts/package.json b/packages/sdk-ts/package.json index 8a633dba6..7353dd095 100644 --- a/packages/sdk-ts/package.json +++ b/packages/sdk-ts/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/sdk-ts", "description": "SDK in TypeScript for building Injective applications in a browser, node, and react native environment.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "license": "Apache-2.0", "author": { diff --git a/packages/wallet-ts/package.json b/packages/wallet-ts/package.json index 8562efe19..3ecf6f82c 100644 --- a/packages/wallet-ts/package.json +++ b/packages/wallet-ts/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-ts", "description": "A convenient way to use and interact with different types of wallets on Injective.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -83,7 +83,7 @@ "@ethereumjs/tx": "^4.1.1", "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", "@keplr-wallet/cosmos": "^0.12.71", diff --git a/packages/wallets/wallet-base/package.json b/packages/wallets/wallet-base/package.json index 0eb838388..7bfcc464e 100644 --- a/packages/wallets/wallet-base/package.json +++ b/packages/wallets/wallet-base/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-base", "description": "Base wallet strategy for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -59,7 +59,7 @@ "@ethereumjs/tx": "^4.1.1", "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", "alchemy-sdk": "^3.4.7", diff --git a/packages/wallets/wallet-core/package.json b/packages/wallets/wallet-core/package.json index 7fc1396a9..ec49f106b 100644 --- a/packages/wallets/wallet-core/package.json +++ b/packages/wallets/wallet-core/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-core", "description": "Core wallet strategy", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -57,7 +57,7 @@ "dependencies": { "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@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", diff --git a/packages/wallets/wallet-cosmos-strategy/package.json b/packages/wallets/wallet-cosmos-strategy/package.json index 1f8ca0d61..4492ac9ba 100644 --- a/packages/wallets/wallet-cosmos-strategy/package.json +++ b/packages/wallets/wallet-cosmos-strategy/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-cosmos-strategy", "description": "Wallet Cosmos Strategy with instantiated wallets", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -59,13 +59,13 @@ "@ethereumjs/tx": "^4.1.1", "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1", - "@injectivelabs/wallet-core": "^1.14.33-beta.1", - "@injectivelabs/wallet-cosmos": "^1.14.33-beta.1", - "@injectivelabs/wallet-cosmostation": "^1.14.33-beta.1", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", + "@injectivelabs/wallet-core": "^1.14.33-beta.2", + "@injectivelabs/wallet-cosmos": "^1.14.33-beta.2", + "@injectivelabs/wallet-cosmostation": "^1.14.33-beta.2", "alchemy-sdk": "^3.4.7", "eip1193-provider": "^1.0.1", "eth-sig-util": "^3.0.1", diff --git a/packages/wallets/wallet-cosmos/package.json b/packages/wallets/wallet-cosmos/package.json index f451473b7..7cb16b080 100644 --- a/packages/wallets/wallet-cosmos/package.json +++ b/packages/wallets/wallet-cosmos/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-cosmos", "description": "Cosmos wallet strategies for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -61,10 +61,10 @@ "@cosmjs/stargate": "^0.32.3", "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", "@keplr-wallet/cosmos": "^0.12.71", "@keplr-wallet/types": "^0.12.71", "shx": "^0.3.3" diff --git a/packages/wallets/wallet-cosmostation/package.json b/packages/wallets/wallet-cosmostation/package.json index 5398a4e3a..3f64e693a 100644 --- a/packages/wallets/wallet-cosmostation/package.json +++ b/packages/wallets/wallet-cosmostation/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-cosmostation", "description": "Cosmostation strategy for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -58,10 +58,10 @@ "@cosmjs/proto-signing": "^0.32.3", "@cosmostation/extension-client": "^0.1.15", "@injectivelabs/exceptions": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", "@walletconnect/ethereum-provider": "^2.12.2" }, "gitHead": "6442ae377bbfb3459d2fb3a44c650630a5b7f445", diff --git a/packages/wallets/wallet-evm/package.json b/packages/wallets/wallet-evm/package.json index a64a0e3e7..78d0a0387 100644 --- a/packages/wallets/wallet-evm/package.json +++ b/packages/wallets/wallet-evm/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-evm", "description": "EVM wallet strategies for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -57,7 +57,7 @@ "dependencies": { "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@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", diff --git a/packages/wallets/wallet-ledger/package.json b/packages/wallets/wallet-ledger/package.json index 7d743b6ba..7c4fa1284 100644 --- a/packages/wallets/wallet-ledger/package.json +++ b/packages/wallets/wallet-ledger/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-ledger", "description": "Ledger wallet strategy for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -59,10 +59,10 @@ "@ethereumjs/tx": "^4.1.1", "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", "@ledgerhq/hw-app-cosmos": "^6.29.5", "@ledgerhq/hw-app-eth": "6.35.6", "@ledgerhq/hw-transport": "6.30.4", diff --git a/packages/wallets/wallet-magic/package.json b/packages/wallets/wallet-magic/package.json index 49a91164a..b94f4152e 100644 --- a/packages/wallets/wallet-magic/package.json +++ b/packages/wallets/wallet-magic/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-magic", "description": "Magic wallet strategy for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -56,10 +56,10 @@ }, "dependencies": { "@injectivelabs/exceptions": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", "@magic-ext/cosmos": "23.9.1", "@magic-ext/oauth2": "9.9.0", "magic-sdk": "28.9.0" diff --git a/packages/wallets/wallet-private-key/package.json b/packages/wallets/wallet-private-key/package.json index 194afab6f..ce87e0168 100644 --- a/packages/wallets/wallet-private-key/package.json +++ b/packages/wallets/wallet-private-key/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-private-key", "description": "Private key wallet strategy for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -56,10 +56,10 @@ }, "dependencies": { "@injectivelabs/exceptions": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1" + "@injectivelabs/wallet-base": "^1.14.33-beta.2" }, "gitHead": "6442ae377bbfb3459d2fb3a44c650630a5b7f445", "typedoc": { diff --git a/packages/wallets/wallet-strategy/package.json b/packages/wallets/wallet-strategy/package.json index ccc32ed3e..9f18354c8 100644 --- a/packages/wallets/wallet-strategy/package.json +++ b/packages/wallets/wallet-strategy/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-strategy", "description": "Wallet strategy with instantiated wallets", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -59,19 +59,19 @@ "@ethereumjs/tx": "^4.1.1", "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1", - "@injectivelabs/wallet-core": "^1.14.33-beta.1", - "@injectivelabs/wallet-cosmos": "^1.14.33-beta.1", - "@injectivelabs/wallet-cosmostation": "^1.14.33-beta.1", - "@injectivelabs/wallet-evm": "^1.14.33-beta.1", - "@injectivelabs/wallet-ledger": "^1.14.33-beta.1", - "@injectivelabs/wallet-magic": "^1.14.33-beta.1", - "@injectivelabs/wallet-private-key": "^1.14.33-beta.1", - "@injectivelabs/wallet-trezor": "^1.14.33-beta.1", - "@injectivelabs/wallet-wallet-connect": "^1.14.33-beta.1", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", + "@injectivelabs/wallet-core": "^1.14.33-beta.2", + "@injectivelabs/wallet-cosmos": "^1.14.33-beta.2", + "@injectivelabs/wallet-cosmostation": "^1.14.33-beta.2", + "@injectivelabs/wallet-evm": "^1.14.33-beta.2", + "@injectivelabs/wallet-ledger": "^1.14.33-beta.2", + "@injectivelabs/wallet-magic": "^1.14.33-beta.2", + "@injectivelabs/wallet-private-key": "^1.14.33-beta.2", + "@injectivelabs/wallet-trezor": "^1.14.33-beta.2", + "@injectivelabs/wallet-wallet-connect": "^1.14.33-beta.2", "alchemy-sdk": "^3.4.7", "eip1193-provider": "^1.0.1", "eth-sig-util": "^3.0.1", diff --git a/packages/wallets/wallet-trezor/package.json b/packages/wallets/wallet-trezor/package.json index aee153f18..6cd324310 100644 --- a/packages/wallets/wallet-trezor/package.json +++ b/packages/wallets/wallet-trezor/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-trezor", "description": "Trezor wallet strategy for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -59,10 +59,10 @@ "@ethereumjs/tx": "^4.1.1", "@injectivelabs/exceptions": "^1.14.32", "@injectivelabs/networks": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", "@trezor/connect-web": "9.2.1", "alchemy-sdk": "^3.4.7", "eip1193-provider": "^1.0.1", diff --git a/packages/wallets/wallet-wallet-connect/package.json b/packages/wallets/wallet-wallet-connect/package.json index 97d315081..693c92594 100644 --- a/packages/wallets/wallet-wallet-connect/package.json +++ b/packages/wallets/wallet-wallet-connect/package.json @@ -1,7 +1,7 @@ { "name": "@injectivelabs/wallet-wallet-connect", "description": "Wallet connect strategy for use with @injectivelabs/wallet-core.", - "version": "1.14.33-beta.1", + "version": "1.14.33-beta.2", "sideEffects": false, "author": { "name": "InjectiveLabs", @@ -56,10 +56,10 @@ }, "dependencies": { "@injectivelabs/exceptions": "^1.14.32", - "@injectivelabs/sdk-ts": "^1.14.33-beta.1", + "@injectivelabs/sdk-ts": "^1.14.33-beta.2", "@injectivelabs/ts-types": "^1.14.32", "@injectivelabs/utils": "^1.14.32", - "@injectivelabs/wallet-base": "^1.14.33-beta.1", + "@injectivelabs/wallet-base": "^1.14.33-beta.2", "@walletconnect/ethereum-provider": "^2.12.2" }, "gitHead": "6442ae377bbfb3459d2fb3a44c650630a5b7f445", From 5ac0bc3033c5e4b7abdb0494c07edde3c3cf6db5 Mon Sep 17 00:00:00 2001 From: thomasRalee Date: Fri, 29 Nov 2024 03:31:34 +0800 Subject: [PATCH 5/6] chore: wallet strategy enhancement --- .../wallet-strategy/strategies/Ledger/Base.ts | 32 ++-- .../wallets/wallet-base/src/utils/index.ts | 3 + .../wallets/wallet-base/src/utils/wallet.ts | 9 + packages/wallets/wallet-core/package.json | 2 +- .../src/strategy/BaseWalletStrategy.ts | 2 +- .../wallets/wallet-cosmos/src/cosmos.d.ts | 1 + .../wallets/wallet-cosmos/src/data/index.ts | 8 + packages/wallets/wallet-cosmos/src/index.ts | 1 + .../wallet-cosmos/src/strategy/strategy.ts | 26 ++- .../wallets/wallet-cosmos/src/utils/index.ts | 60 ++++++ packages/wallets/wallet-cosmos/src/wallet.ts | 39 ++-- .../wallets/wallet-cosmostation/src/index.ts | 1 + .../wallet-cosmostation/src/utils/index.ts | 9 + packages/wallets/wallet-evm/package.json | 2 +- packages/wallets/wallet-evm/src/data/index.ts | 9 + .../wallet-evm/src/strategy/strategy.ts | 30 ++- .../wallets/wallet-evm/src/utils/index.ts | 83 ++++++-- .../src/strategy/WalletStrategy.ts | 180 ----------------- .../wallet-strategy/src/strategy/index.ts | 181 +++++++++++++++++- yarn.lock | 78 +------- 20 files changed, 424 insertions(+), 332 deletions(-) create mode 100644 packages/wallets/wallet-cosmos/src/data/index.ts create mode 100644 packages/wallets/wallet-cosmos/src/utils/index.ts create mode 100644 packages/wallets/wallet-cosmostation/src/utils/index.ts create mode 100644 packages/wallets/wallet-evm/src/data/index.ts delete mode 100644 packages/wallets/wallet-strategy/src/strategy/WalletStrategy.ts 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/index.ts b/packages/wallets/wallet-base/src/utils/index.ts index ead0c7095..2782fbce9 100644 --- a/packages/wallets/wallet-base/src/utils/index.ts +++ b/packages/wallets/wallet-base/src/utils/index.ts @@ -4,3 +4,6 @@ export * from './wallet.js' export * from './constants.js' export * from './alchemy.js' export * from './cosmos.js' + +export const capitalize = (str: string): string => + str[0].toUpperCase() + str.slice(1) diff --git a/packages/wallets/wallet-base/src/utils/wallet.ts b/packages/wallets/wallet-base/src/utils/wallet.ts index 3daff13cb..fceba4d4c 100644 --- a/packages/wallets/wallet-base/src/utils/wallet.ts +++ b/packages/wallets/wallet-base/src/utils/wallet.ts @@ -19,6 +19,15 @@ export const isEthWallet = (wallet: Wallet): boolean => export const isCosmosWallet = (wallet: Wallet): boolean => !isEthWallet(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 => [ Wallet.Magic, 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..2c646d27c 100644 --- a/packages/wallets/wallet-core/src/strategy/BaseWalletStrategy.ts +++ b/packages/wallets/wallet-core/src/strategy/BaseWalletStrategy.ts @@ -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..7b7bf354e 100644 --- a/packages/wallets/wallet-cosmos/src/strategy/strategy.ts +++ b/packages/wallets/wallet-cosmos/src/strategy/strategy.ts @@ -22,6 +22,7 @@ import { } from '@injectivelabs/exceptions' import { Wallet, + capitalize, StdSignDoc, WalletAction, WalletDeviceType, @@ -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..1cdb7ed87 --- /dev/null +++ b/packages/wallets/wallet-cosmos/src/utils/index.ts @@ -0,0 +1,60 @@ +import type { Keplr } from '@keplr-wallet/types' +import { ChainId } from '@injectivelabs/ts-types' +import { PublicKey } from '@injectivelabs/sdk-ts' +import { Wallet, capitalize } from '@injectivelabs/wallet-base' +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?: Keplr + keplr?: Keplr + ninji?: Keplr + } + + switch (wallet) { + case Wallet.Keplr: + return $window.keplr !== undefined + case Wallet.Ninji: + return $window.ninji !== undefined + case Wallet.Leap: + return $window.leap !== 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 keplr = new CosmosWallet({ chainId, wallet }) + const key = await keplr.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..ceabf977f 100644 --- a/packages/wallets/wallet-cosmos/src/wallet.ts +++ b/packages/wallets/wallet-cosmos/src/wallet.ts @@ -19,8 +19,8 @@ import { WalletErrorActionModule, } from '@injectivelabs/exceptions' import { BroadcastMode } from '@cosmjs/launchpad' -import { Wallet } from '@injectivelabs/wallet-base' import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts' +import { Wallet, capitalize } from '@injectivelabs/wallet-base' import { SigningStargateClient, StdFee } from '@cosmjs/stargate' import type { EncodeObject, OfflineDirectSigner } from '@cosmjs/proto-signing' @@ -35,10 +35,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 +49,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 +78,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 +139,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 +248,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 +287,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 +339,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 +352,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 +381,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 +397,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 +419,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/data/index.ts b/packages/wallets/wallet-evm/src/data/index.ts new file mode 100644 index 000000000..668766cbe --- /dev/null +++ b/packages/wallets/wallet-evm/src/data/index.ts @@ -0,0 +1,9 @@ +import { Wallet } from '@injectivelabs/wallet-base' + +export const evmWallets = [ + Wallet.BitGet, + Wallet.Phantom, + Wallet.Metamask, + Wallet.OkxWallet, + Wallet.TrustWallet, +] diff --git a/packages/wallets/wallet-evm/src/strategy/strategy.ts b/packages/wallets/wallet-evm/src/strategy/strategy.ts index 3af529d7d..484951a62 100644 --- a/packages/wallets/wallet-evm/src/strategy/strategy.ts +++ b/packages/wallets/wallet-evm/src/strategy/strategy.ts @@ -1,4 +1,12 @@ /* eslint-disable class-methods-use-this */ +import { + TxRaw, + toUtf8, + TxGrpcApi, + TxResponse, + DirectSignResponse, + AminoSignResponse, +} from '@injectivelabs/sdk-ts' import { ErrorType, ErrorContext, @@ -13,6 +21,7 @@ import { } from '@injectivelabs/exceptions' import { Wallet, + capitalize, StdSignDoc, WalletAction, WalletDeviceType, @@ -26,14 +35,6 @@ import { } from '@injectivelabs/wallet-base' import { sleep } from '@injectivelabs/utils' import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types' -import { - TxRaw, - toUtf8, - TxGrpcApi, - TxResponse, - DirectSignResponse, - AminoSignResponse, -} from '@injectivelabs/sdk-ts' import { getBitGetProvider, getPhantomProvider, @@ -41,14 +42,7 @@ import { getOkxWalletProvider, getTrustWalletProvider, } from './utils/index.js' - -const evmWallets = [ - Wallet.BitGet, - Wallet.Phantom, - Wallet.Metamask, - Wallet.OkxWallet, - Wallet.TrustWallet, -] +import { evmWallets } from '../data/index.js' export class EvmWallet extends BaseConcreteStrategy @@ -65,7 +59,9 @@ export class EvmWallet if (!evmWallets.includes(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..97b88bd1b 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, + capitalize, + BrowserEip1993Provider, +} from '@injectivelabs/wallet-base' 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' +import { evmWallets } from '../data/index.js' + +export const getEvmProvider = async ( + wallet: Wallet, +): Promise => { + if (!evmWallets.includes(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 (!evmWallets.includes(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-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..013e6bbbb 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, + 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/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== From 5f4eec8c1032d9de3503cb4e28d982328f7dbd0a Mon Sep 17 00:00:00 2001 From: Bojan Angjelkoski Date: Fri, 29 Nov 2024 14:04:05 +0100 Subject: [PATCH 6/6] refactor: minor --- packages/utils/src/formatters.ts | 3 +++ .../wallets/wallet-base/src/utils/index.ts | 3 --- .../wallets/wallet-base/src/utils/wallet.ts | 21 ++++++++++--------- .../src/strategy/BaseWalletStrategy.ts | 6 +++--- .../wallet-cosmos/src/strategy/strategy.ts | 2 +- .../wallets/wallet-cosmos/src/utils/index.ts | 18 +++++++++------- packages/wallets/wallet-cosmos/src/wallet.ts | 3 ++- packages/wallets/wallet-evm/src/data/index.ts | 9 -------- packages/wallets/wallet-evm/src/index.ts | 1 + .../wallet-evm/src/strategy/strategy.ts | 7 +++---- .../wallets/wallet-evm/src/utils/index.ts | 8 +++---- .../wallet-strategy/src/strategy/index.ts | 4 ++-- 12 files changed, 41 insertions(+), 44 deletions(-) delete mode 100644 packages/wallets/wallet-evm/src/data/index.ts 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/wallets/wallet-base/src/utils/index.ts b/packages/wallets/wallet-base/src/utils/index.ts index 2782fbce9..ead0c7095 100644 --- a/packages/wallets/wallet-base/src/utils/index.ts +++ b/packages/wallets/wallet-base/src/utils/index.ts @@ -4,6 +4,3 @@ export * from './wallet.js' export * from './constants.js' export * from './alchemy.js' export * from './cosmos.js' - -export const capitalize = (str: string): string => - str[0].toUpperCase() + str.slice(1) diff --git a/packages/wallets/wallet-base/src/utils/wallet.ts b/packages/wallets/wallet-base/src/utils/wallet.ts index fceba4d4c..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,16 @@ 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 => [ @@ -38,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/src/strategy/BaseWalletStrategy.ts b/packages/wallets/wallet-core/src/strategy/BaseWalletStrategy.ts index 2c646d27c..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}`), ) diff --git a/packages/wallets/wallet-cosmos/src/strategy/strategy.ts b/packages/wallets/wallet-cosmos/src/strategy/strategy.ts index 7b7bf354e..84b968597 100644 --- a/packages/wallets/wallet-cosmos/src/strategy/strategy.ts +++ b/packages/wallets/wallet-cosmos/src/strategy/strategy.ts @@ -22,7 +22,6 @@ import { } from '@injectivelabs/exceptions' import { Wallet, - capitalize, StdSignDoc, WalletAction, WalletDeviceType, @@ -32,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] diff --git a/packages/wallets/wallet-cosmos/src/utils/index.ts b/packages/wallets/wallet-cosmos/src/utils/index.ts index 1cdb7ed87..9b06c3718 100644 --- a/packages/wallets/wallet-cosmos/src/utils/index.ts +++ b/packages/wallets/wallet-cosmos/src/utils/index.ts @@ -1,16 +1,18 @@ -import type { Keplr } from '@keplr-wallet/types' +import type { Keplr as CosmosBrowserWallet } from '@keplr-wallet/types' import { ChainId } from '@injectivelabs/ts-types' import { PublicKey } from '@injectivelabs/sdk-ts' -import { Wallet, capitalize } from '@injectivelabs/wallet-base' +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?: Keplr - keplr?: Keplr - ninji?: Keplr + leap?: CosmosBrowserWallet + keplr?: CosmosBrowserWallet + ninji?: CosmosBrowserWallet + oWallet?: CosmosBrowserWallet } switch (wallet) { @@ -20,6 +22,8 @@ export const isCosmosWalletInstalled = (wallet: Wallet) => { return $window.ninji !== undefined case Wallet.Leap: return $window.leap !== undefined + case Wallet.OWallet: + return $window.oWallet !== undefined default: return false } @@ -40,8 +44,8 @@ export const confirmCosmosAddress = async ({ ) } - const keplr = new CosmosWallet({ chainId, wallet }) - const key = await keplr.getKey() + const cosmosWallet = new CosmosWallet({ chainId, wallet }) + const key = await cosmosWallet.getKey() const publicKey = PublicKey.fromBase64( Buffer.from(key.pubKey).toString('base64'), ) diff --git a/packages/wallets/wallet-cosmos/src/wallet.ts b/packages/wallets/wallet-cosmos/src/wallet.ts index ceabf977f..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 { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts' -import { Wallet, capitalize } from '@injectivelabs/wallet-base' +import { Wallet } from '@injectivelabs/wallet-base' import { SigningStargateClient, StdFee } from '@cosmjs/stargate' import type { EncodeObject, OfflineDirectSigner } from '@cosmjs/proto-signing' diff --git a/packages/wallets/wallet-evm/src/data/index.ts b/packages/wallets/wallet-evm/src/data/index.ts deleted file mode 100644 index 668766cbe..000000000 --- a/packages/wallets/wallet-evm/src/data/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Wallet } from '@injectivelabs/wallet-base' - -export const evmWallets = [ - Wallet.BitGet, - Wallet.Phantom, - Wallet.Metamask, - Wallet.OkxWallet, - Wallet.TrustWallet, -] 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 484951a62..bfb786f1a 100644 --- a/packages/wallets/wallet-evm/src/strategy/strategy.ts +++ b/packages/wallets/wallet-evm/src/strategy/strategy.ts @@ -1,4 +1,5 @@ /* eslint-disable class-methods-use-this */ +import { isEvmBrowserWallet } from '@injectivelabs/wallet-base' import { TxRaw, toUtf8, @@ -21,7 +22,6 @@ import { } from '@injectivelabs/exceptions' import { Wallet, - capitalize, StdSignDoc, WalletAction, WalletDeviceType, @@ -33,7 +33,7 @@ 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 { getBitGetProvider, @@ -42,7 +42,6 @@ import { getOkxWalletProvider, getTrustWalletProvider, } from './utils/index.js' -import { evmWallets } from '../data/index.js' export class EvmWallet extends BaseConcreteStrategy @@ -57,7 +56,7 @@ export class EvmWallet ) { super(args) - if (!evmWallets.includes(args.wallet)) { + if (!isEvmBrowserWallet(args.wallet)) { throw new WalletException( 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 97b88bd1b..b8bd831a8 100644 --- a/packages/wallets/wallet-evm/src/utils/index.ts +++ b/packages/wallets/wallet-evm/src/utils/index.ts @@ -1,8 +1,9 @@ import { Wallet, - capitalize, + 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' @@ -10,12 +11,11 @@ import { getBitGetProvider } from '../strategy/utils/bitget.js' import { getPhantomProvider } from '../strategy/utils/phantom.js' import { getMetamaskProvider } from '../strategy/utils/metamask.js' import { getTrustWalletProvider } from '../strategy/utils/trustWallet.js' -import { evmWallets } from '../data/index.js' export const getEvmProvider = async ( wallet: Wallet, ): Promise => { - if (!evmWallets.includes(wallet)) { + if (!isEvmBrowserWallet(wallet)) { throw new WalletException( new Error(`Evm Wallet for ${capitalize(wallet)} is not supported.`), ) @@ -62,7 +62,7 @@ export const updateEvmNetwork = async ( wallet: Wallet, chainId: EthereumChainId, ) => { - if (!evmWallets.includes(wallet)) { + if (!isEvmBrowserWallet(wallet)) { throw new WalletException( new Error(`Evm Wallet for ${capitalize(wallet)} is not supported.`), ) diff --git a/packages/wallets/wallet-strategy/src/strategy/index.ts b/packages/wallets/wallet-strategy/src/strategy/index.ts index 013e6bbbb..6b44fa8ab 100644 --- a/packages/wallets/wallet-strategy/src/strategy/index.ts +++ b/packages/wallets/wallet-strategy/src/strategy/index.ts @@ -1,6 +1,6 @@ import { Wallet, - isEthWallet, + isEvmWallet, MagicMetadata, ConcreteStrategiesArg, ConcreteWalletStrategy, @@ -49,7 +49,7 @@ const createStrategy = ({ * If we only want to use Cosmos Native Wallets * We are not creating strategies for Ethereum Native Wallets */ - if (isEthWallet(wallet) && ethereumWalletsDisabled(args)) { + if (isEvmWallet(wallet) && ethereumWalletsDisabled(args)) { return undefined }