Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor wallet strategies #508

Merged
merged 30 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fddafde
chore: refactor ledger wallet strategy
billyjacoby Oct 4, 2024
f625e05
fix: rm unused tsconfig ref
billyjacoby Oct 4, 2024
cacaae7
fix: refactor Wallets instead of WalletStrategies
billyjacoby Oct 7, 2024
41b773a
fix: createStrategy types
billyjacoby Oct 7, 2024
66ec741
Merge branch 'dev' into chore/refactor-wallet-strategies
bangjelkoski Oct 10, 2024
97770f4
refactor: initial
bangjelkoski Oct 10, 2024
953a95e
refactor: build working
bangjelkoski Oct 10, 2024
8dd866f
refactor: final
bangjelkoski Oct 10, 2024
0e921a3
feat: decouple keplr
bangjelkoski Oct 10, 2024
d9ac8c9
chore: abstract all evm wallets to wallet-evm package
ThomasRalee Oct 15, 2024
9807132
feat: refactor trezor wallet
billyjacoby Oct 15, 2024
881b81c
feat: add private key wallet
billyjacoby Oct 15, 2024
6b52505
chore: abstract magic wallet
ThomasRalee Oct 16, 2024
ed95846
chore: abstract trust wallet
ThomasRalee Oct 16, 2024
0896017
chore: abstract wallet connect
ThomasRalee Oct 16, 2024
673b3bf
chore: abstract cosmos wallets
ThomasRalee Oct 18, 2024
3605f8e
chore: abstract cosmostation wallet
ThomasRalee Oct 18, 2024
5f27985
fix: add ethereumAddress from wallet
billyjacoby Oct 18, 2024
ea5a1c2
refactor: rename to wallet-wallet-connect
bangjelkoski Oct 23, 2024
e217429
chore: merge conflicts
bangjelkoski Oct 23, 2024
7b50184
fix: build cache paths
bangjelkoski Oct 23, 2024
790bff5
chore: add docs for creating a wallet-strategy
bangjelkoski Oct 23, 2024
6a2c294
chore: cleanup deps
billyjacoby Oct 24, 2024
0a8d897
fix: blank dist folder
bangjelkoski Oct 24, 2024
d598330
Merge branch 'chore/refactor-wallet-strategies' of github.com:Injecti…
bangjelkoski Oct 24, 2024
7152d3e
chore: copy
bangjelkoski Oct 24, 2024
ec17ff3
chore: wallet-cosmos add support for owallet
ThomasRalee Oct 25, 2024
07e1aff
chore: minor copy
bangjelkoski Oct 25, 2024
8dc1f82
chore: update docs
billyjacoby Oct 29, 2024
9127634
refactor: imports, added cosmos wallet strategy, removed deprecated m…
bangjelkoski Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"editor.renderFinalNewline": "on",
"cSpell.words": [
"chronos"
]
}
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"editor.renderFinalNewline": "on",
"cSpell.words": ["chronos"],
"[json][jsonc][javascript][javascriptreact][typescript][typescriptreact][vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": [
"source.formatDocument",
"source.fixAll.eslint"
]
}
}
4 changes: 4 additions & 0 deletions etc/bootstrapEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const main = () => {
const packages = getDirectories()

packages.forEach((packageName) => {
if (packageName === 'wallets') {
return
}

const path = `packages/${packageName}/dist`
const esmPath = `packages/${packageName}/dist/esm`
const cjsPath = `packages/${packageName}/dist/cjs`
Expand Down
47 changes: 47 additions & 0 deletions etc/replacements-ledger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { readFile, writeFile } = require('fs')

const isCJS = process.env.BUILD_MODE.includes('cjs')
const isESM = process.env.BUILD_MODE.includes('esm')

const REPLACEMENT_PAIRS = [
{
path: './src/strategy/Ledger/Base.ts',
cjs: '@ledgerhq/hw-app-eth/lib/services/ledger',
esm: '@ledgerhq/hw-app-eth/lib-es/services/ledger',
},
]

for (const pair of REPLACEMENT_PAIRS) {
readFile(pair.path, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err)
return
}

if (isCJS) {
const updatedData = data.replace(new RegExp(pair.esm, 'g'), pair.cjs)

writeFile(pair.path, updatedData, 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err)
return
}

console.log(`Replaced in ${pair.path} for CJS`)
})
}

if (isESM) {
const updatedData = data.replace(new RegExp(pair.cjs, 'g'), pair.esm)

writeFile(pair.path, updatedData, 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err)
return
}

console.log(`Replaced in ${pair.path} for ESM`)
})
}
})
}
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"npmClient": "yarn",
"name": "injective-ts",
"packages": ["packages/*"],
"packages": ["packages/*", "packages/wallets/*"],
"version": "independent",
"useWorkspaces": true,
"command": {
"version": {
"message": "chore(release): publish"
"message": "chore: release"
},
"publish": {
"conventionalCommits": true
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"repository": "https://github.com/InjectiveLabs/injective-ts",
"workspaces": {
"packages": [
"packages/*"
"packages/*",
"packages/wallets/*"
]
},
"scripts": {
Expand All @@ -34,9 +35,6 @@
"test:sdk-ts:core:modules": "jest ./packages/sdk-ts/src/core/modules",
"test:sdk-ts:core": "jest ./packages/sdk-ts/src/core",
"test:sdk-ts:client": "jest ./packages/sdk-ts/src/client",
"test:bridge-ts": "jest ./packages/bridge-ts/src",
"test:sdk-ui-ts": "jest ./packages/sdk-ui-ts/src",
"test:token-metadata": "jest ./packages/token-metadata/test",
"test:ci": "jest --coverage --ci --reporters='jest-junit'",
"coverage": "jest --coverage",
"coverage:unit": "yarn test:unit --coverage",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { INJ_DENOM } from '@injectivelabs/utils'
// import { INJ_DENOM } from '@injectivelabs/utils'
import { mockFactory } from '@injectivelabs/test-utils'
import { IndexerGrpcAccountPortfolioTransformer } from '../transformers'
import { IndexerGrpcAccountPortfolioApi } from './IndexerGrpcPortfolioApi'
Expand Down Expand Up @@ -34,25 +34,25 @@ describe('IndexerGrpcAccountPortfolioApi', () => {
})
})

test('fetchAccountPortfolioTokenHolders', async () => {
try {
const response =
await indexerGrpcPortfolioApi.fetchAccountPortfolioTokenHolders({
denom: INJ_DENOM,
})
// test('fetchAccountPortfolioTokenHolders', async () => {
// try {
// const response =
// await indexerGrpcPortfolioApi.fetchAccountPortfolioTokenHolders({
// denom: INJ_DENOM,
// })

expect(response).toBeDefined()
expect(response).toEqual(
expect.objectContaining<
ReturnType<
typeof IndexerGrpcAccountPortfolioTransformer.tokenHoldersResponseToTokenHolders
>
>(response),
)
} catch (e) {
console.error(
'IndexerGrpcAccountPortfolioApi.fetchAccountPortfolioTokenHolders => ' +
(e as any).message,
)
}
})
// expect(response).toBeDefined()
// expect(response).toEqual(
// expect.objectContaining<
// ReturnType<
// typeof IndexerGrpcAccountPortfolioTransformer.tokenHoldersResponseToTokenHolders
// >
// >(response),
// )
// } catch (e) {
// console.error(
// 'IndexerGrpcAccountPortfolioApi.fetchAccountPortfolioTokenHolders => ' +
// (e as any).message,
// )
// }
// })
2 changes: 1 addition & 1 deletion packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateArbitrarySignDoc } from '../modules'
import { generateArbitrarySignDoc } from '../tx'
import { PrivateKey } from './PrivateKey'

const pk = 'f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class MsgBroadcasterWithPk {
const tx = {
...transaction,
msgs: msgs,
ethereumAddress: ethereumWallet
} as MsgBroadcasterTxOptions & { ethereumAddress: string }

const web3Msgs = msgs.map((msg) => msg.toWeb3())
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk-ts/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DirectSignResponse } from '@cosmjs/proto-signing'
import { AminoSignResponse } from '@cosmjs/amino'
import {
CosmosTxV1Beta1Tx,
CosmosBaseV1Beta1Coin,
Expand All @@ -23,5 +24,6 @@ export enum StreamOperation {

export type GrpcCoin = CosmosBaseV1Beta1Coin.Coin
export type TxRaw = CosmosTxV1Beta1Tx.TxRaw
export type SignDoc = CosmosTxV1Beta1Tx.SignDoc

export { DirectSignResponse }
export { DirectSignResponse, AminoSignResponse }
1 change: 1 addition & 0 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"start": "node dist/index.js"
},
"dependencies": {
"@injectivelabs/exceptions": "^1.14.13",
"@injectivelabs/networks": "^1.14.13",
"@injectivelabs/ts-types": "^1.14.15-beta.0",
"@injectivelabs/utils": "^1.14.15-beta.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/test-utils/tsconfig.build.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
{
"path": "../exceptions/tsconfig.build.esm.json"
},
{
"path": "../utils/tsconfig.build.esm.json"
},
{
"path": "../networks/tsconfig.build.esm.json"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/test-utils/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
{
"path": "../exceptions/tsconfig.build.json"
},
{
"path": "../utils/tsconfig.build.json"
},
{
"path": "../networks/tsconfig.build.json"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/ts-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ export interface PaginationOption {
export interface Constructable<T> {
new (...args: never): T
}

export type UnwrappedPromise<T> = T extends Promise<infer Return> ? Return : T
2 changes: 2 additions & 0 deletions packages/wallet-ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

_A convenient way to use different types of wallets on Injective._

**DEPRECATED: PLEASE USE `@injectivelabs/wallet-strategy`**

---

## 📚 Installation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
TxRaw,
TxResponse,
waitTxBroadcasted,
AminoSignResponse,
DirectSignResponse,
createTxRawFromSigResponse,
createSignDocFromTransaction,
} from '@injectivelabs/sdk-ts'
import type { DirectSignResponse } from '@cosmjs/proto-signing'
import { StdSignDoc } from '@keplr-wallet/types'
import { AminoSignResponse } from '@cosmjs/launchpad'
import { LeapWallet } from '../../../utils/wallets/leap'
import { WalletAction, WalletDeviceType } from '../../../types/enums'
import { ConcreteCosmosWalletStrategy } from '../../types/strategy'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
TxRaw,
TxResponse,
waitTxBroadcasted,
AminoSignResponse,
DirectSignResponse,
createTxRawFromSigResponse,
createSignDocFromTransaction,
} from '@injectivelabs/sdk-ts'
import type { DirectSignResponse } from '@cosmjs/proto-signing'
import { StdSignDoc } from '@keplr-wallet/types'
import { AminoSignResponse } from '@cosmjs/launchpad'
import { NinjiWallet } from '../../../utils/wallets/ninji'
import { WalletAction, WalletDeviceType } from '../../../types/enums'
import { ConcreteCosmosWalletStrategy } from '../../types/strategy'
Expand Down
60 changes: 60 additions & 0 deletions packages/wallets/wallet-base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 🌟 Injective Protocol - Wallet Base

<!-- TODO -->

[![downloads](https://img.shields.io/npm/dm/@injectivelabs/wallet-base.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-base)
[![npm-version](https://img.shields.io/npm/v/@injectivelabs/wallet-base.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-base)
[![license](https://img.shields.io/npm/l/express.svg)]()

_Base Package for the Wallet Strategy._

---

## 📚 Installation

```bash
yarn add @injectivelabs/wallet-base
```

---

## 📖 Documentation

<!-- TODO -->

Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)

---

## 📜 Contribution

**Contribution guides and practices will be available once there is a stable foundation of the whole package set within the `injective-ts` repo.**

---

## ⛑ Support

Reach out to us at one of the following places!

- Website at <a href="https://injective.com" target="_blank">`injective.com`</a>
- Twitter at <a href="https://twitter.com/Injective_" target="_blank">`@Injective`</a>
- Discord at <a href="https://discord.com/invite/NK4qdbv" target="_blank">`Discord`</a>
- Telegram at <a href="https://t.me/joininjective" target="_blank">`Telegram`</a>

---

## 🔓 License

Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)

<a href="https://iili.io/mNneZN.md.png"><img src="https://iili.io/mNneZN.md.png" style="width: 300px; max-width: 100%; height: auto" />

Originally released by Injective Labs Inc. under: <br />
Apache License <br />
Version 2.0, January 2004 <br />
http://www.apache.org/licenses/

<p>&nbsp;</p>
<div align="center">
<sub><em>Powering the future of decentralized finance.</em></sub>
</div>
63 changes: 63 additions & 0 deletions packages/wallets/wallet-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@injectivelabs/wallet-base",
"description": "Base wallet strategy for use with @injectivelabs/wallet-core.",
"version": "0.0.1",
"sideEffects": false,
"author": {
"name": "InjectiveLabs",
"email": "[email protected]"
},
"license": "Apache-2.0",
"types": "dist/cjs/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"files": [
"dist"
],
"_moduleAliases": {
"~wallet-base": "dist"
},
"scripts": {
"postinstall": "link-module-alias",
"build:cjs": "BUILD_MODE=cjs tsc --build tsconfig.build.json",
"build:esm": "BUILD_MODE=esm tsc --build tsconfig.build.esm.json",
"build": "yarn build:esm && yarn build:cjs && yarn build:post && link-module-alias",
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post && link-module-alias",
"build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
"clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
"test": "jest",
"test:watch": "jest --watch",
"test:ci": "jest --coverage --ci --reporters='jest-junit'",
"coverage": "jest --coverage",
"coverage:show": "live-server coverage",
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
"start": "node dist/index.js"
},
"dependencies": {
"@ethereumjs/common": "^3.1.1",
"@ethereumjs/tx": "^4.1.1",
"@injectivelabs/exceptions": "^1.14.14",
"@injectivelabs/networks": "^1.14.15-beta.0",
"@injectivelabs/sdk-ts": "^1.14.15-beta.9",
"@injectivelabs/ts-types": "^1.14.14",
"@injectivelabs/utils": "^1.14.14",
"alchemy-sdk": "^2.6.3",
"eip1193-provider": "^1.0.1",
"eth-sig-util": "^3.0.1",
"ethereumjs-util": "^7.1.0",
"ethers": "^6.5.1",
"hdkey": "^2.0.1",
"link-module-alias": "^1.2.0",
"long": "^5.2.1",
"shx": "^0.3.3"
},
"devDependencies": {
"@types/eth-sig-util": "^2.1.1",
"@types/ethereumjs-util": "^6.1.0",
"@types/hdkey": "^2.0.1"
},
"resolutions": {
"**/libsodium": "npm:@bangjelkoski/noop",
"**/libsodium-wrappers": "npm:@bangjelkoski/noop"
}
}
Loading