Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ jobs:
- name: Set up Node 22.19.0
uses: actions/setup-node@v4
with:
node-version: "22.19.0"
cache: "npm"
node-version: '22.19.0'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm clean-install
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Lint code with standard
run: npm run lint

- name: Run tests
run: npm test
run: npm test
54 changes: 54 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: publish

on:
release:
types: [published]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Node 22.19.0
uses: actions/setup-node@v4
with:
node-version: '22.19.0'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm clean-install
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Lint code with standard
run: npm run lint

- name: Run tests
run: npm test

publish:
needs: test
runs-on: ubuntu-latest
environment: npm-publish

steps:
- uses: actions/checkout@v3

- name: Set up Node 22.19.0
uses: actions/setup-node@v4
with:
node-version: '22.19.0'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm clean-install
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
154 changes: 153 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,153 @@
# @wdk/core
# WDK Core

**WDK** is a simple tool that enables you to manage the WDK wallet and protocol modules through a single object.

### Modules Managed

**Wallet Modules** - Add wallet support for any blockchain:
- `@tetherto/wdk-wallet-evm` - Ethereum, Polygon, Arbitrum
- `@tetherto/wdk-wallet-evm-erc4337` - EVM with no gas fees
- `@tetherto/wdk-wallet-ton` - TON blockchain
- `@tetherto/wdk-wallet-ton-gasless` - TON with no gas fees
- `@tetherto/wdk-wallet-btc` - Bitcoin
- `@tetherto/wdk-wallet-tron` - TRON blockchain
- `@tetherto/wdk-wallet-solana` - Solana blockchain

**Service Modules** - Add swap, bridge, and lending services:
- `@tetherto/wdk-protocol-swap-paraswap-evm` - Token swaps on EVM
- `@tetherto/wdk-protocol-bridge-usdt0-evm` - Bridge tokens between EVM chains
- `@tetherto/wdk-protocol-bridge-usdt0-ton` - Bridge tokens from TON to other chains
- `@tetherto/wdk-protocol-lending-aave-evm` - Lending and borrowing on EVM

**📚 Full module list and docs:** [docs.wallet.tether.io](https://docs.wallet.tether.io)

## Features

- **Module Manager**: Controls and connects all WDK wallet and service modules
- **Wallet Modules**: Works with `@tetherto/wdk-wallet-evm`, `@tetherto/wdk-wallet-evm-erc-4337`, `@tetherto/wdk-wallet-tron` and other wallet packages
- **Service Modules**: Manages `@tetherto/wdk-protocol-bridge-usdt0-evm`, `@tetherto/wdk-protocol-bridge-usdt0-ton` and other service packages
- **One Setup**: Add any WDK module when you need it for any blockchain
- **Simple Control**: Manage all your wallet and service modules in one place

## How to Install

```bash
npm install @tetherto/wdk
```

## Quick Start

```typescript
import WDK from '@tetherto/wdk'
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
import WalletManagerTon from '@tetherto/wdk-wallet-ton'
import ParaswapProtocolEvm from '@tetherto/wdk-protocol-swap-paraswap-evm'
import Usdt0ProtocolTon from '@tetherto/wdk-protocol-bridge-usdt0-ton'

// Set up WDK with wallets and services
const wdk = new WDK(seed) //seed are your twelve word phrase
.registerWallet('ethereum', WalletManagerEvm, ethereumWalletConfig)
.registerWallet('ton', WalletManagerTon, tonWalletConfig)
.registerProtocol('ethereum', 'paraswap', ParaswapProtocolEvm, paraswapProtocolConfig)
.registerProtocol('ton', 'usdt0', Usdt0ProtocolTon, usdt0ProtocolConfig)

// Get accounts using different ways
const ethAccount = await wdk.getAccount('ethereum', 3)
const tonAccount = await wdk.getAccountByPath('ton', "1'/2/3")

// Send transactions directly
const { hash: txHash, fee: txFee } = await ethAccount.sendTransaction(tx)

// Use swap service
const paraswap = ethAccount.getSwapProtocol('paraswap')
const { hash: swapHash, fee: swapFee } = await paraswap.swap(swapOptions)

// Use bridge service
const usdt0 = tonAccount.getBridgeProtocol('usdt0')
const { hash: bridgeHash, fee: bridgeFee } = await usdt0.bridge(bridgeOptions)

// These will throw errors:
// const accountTron = await wdk.getAccount('tron', 5) // no tron wallet added
// const badBridge = accountEth.getBridgeProtocol('usdt0') // no usdt0 for ethereum
// const badSwap = tonAccount.getSwapProtocol('dedust') // no dedust for ton
```

## How to Use

### WDK

#### Start
```typescript
constructor(seed: string | Uint8Array)
```

#### Add Things
- `registerWallet<W>(blockchain: string, wallet: W, config: WalletConfig): WDK`
- `registerProtocol<P>(blockchain: string, label: string, protocol: P, config: ProtocolConfig): WDK`
- `registerMiddleware(blockchain: string, middleware: MiddlewareFunction): WDK`

#### Get Accounts
- `getAccount(blockchain: string, index?: number): Promise<IWalletAccountWithProtocols>`
- `getAccountByPath(blockchain: string, path: string): Promise<IWalletAccountWithProtocols>`
- `getFeeRates(blockchain: string): Promise<FeeRates>`

#### Other Tools
- `dispose(): void`

#### Helper Tools
- `getRandomSeedPhrase(): string`
- `isValidSeedPhrase(seedPhrase: string): boolean`

### Account with Services

Works with a basic wallet account but adds service management:

- `registerProtocol<P>(label: string, protocol: P, config: ProtocolConfig): IWalletAccountWithProtocols`
- `getSwapProtocol(label: string): ISwapProtocol` - Gets the swap service with the given name
- `getBridgeProtocol(label: string): IBridgeProtocol` - Gets the bridge service with the given name
- `getLendingProtocol(label: string): ILendingProtocol` - Gets the lending service with the given name

## How to Use It

### Add Many Blockchains
```typescript
const wdk = new WDK(seed) //seed are your twelve word phrase
.registerWallet('ethereum', WalletManagerEvm, ethereumWalletConfig)
.registerWallet('arbitrum', WalletManagerEvm, arbitrumWalletConfig)
.registerWallet('ton', WalletManagerTon, tonWalletConfig)
```

### Add Services to One Account
```typescript
const account = await wdk.getAccount('ethereum', 0)
account.registerProtocol('paraswap', ParaswapProtocolEvm, paraswapProtocolConfig)

const paraswap = account.getSwapProtocol('paraswap')
const { hash, fee } = await paraswap.swap(swapOptions)

// This will throw an error - no service with this name:
// const uniswap = account.getSwapProtocol('uniswap')
```

### Add Extra Tools to Accounts
```typescript
wdk.registerMiddleware('ethereum', async (account) => {
console.log('New account:', await account.getAddress())
})
```

## License

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Support

For support, please open an issue on the GitHub repository.

## Learn More

For full docs, visit [docs.wallet.tether.io](https://docs.wallet.tether.io)
25 changes: 13 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "@wdk/core",
"name": "@tetherto/wdk",
"version": "1.0.0-beta.2",
"description": "A flexible manager that can register and manage multiple wallet instances for different blockchains dynamically.",
"keywords": ["wdk", "core"],
"keywords": [
"wdk",
"core"
],
"author": "Tether",
"license": "Apache-2.0",
"repository": {
Expand All @@ -20,7 +23,7 @@
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage"
},
"dependencies": {
"@wdk/wallet": "https://github.com/davi0kprogramsthings/wdk-wallet#develop",
"@tetherto/wdk-wallet": "^1.0.0-beta.1",
"bare-wdk-runtime": "2.0.0"
},
"devDependencies": {
Expand All @@ -39,6 +42,10 @@
"default": "./package.json"
}
},
"publishConfig": {
"access": "restricted",
"registry": "https://registry.npmjs.org/"
},
"standard": {
"ignore": [
"bare.js",
Expand Down
8 changes: 4 additions & 4 deletions src/wallet-account-with-protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

'use strict'

import { IWalletAccount, NotImplementedError } from '@wdk/wallet'
import { IWalletAccount, NotImplementedError } from '@tetherto/wdk-wallet'

/** @typedef {import('@wdk/wallet/protocols').ISwapProtocol} ISwapProtocol */
/** @typedef {import('@tetherto/wdk-wallet/protocols').ISwapProtocol} ISwapProtocol */

/** @typedef {import('@wdk/wallet/protocols').IBridgeProtocol} IBridgeProtocol */
/** @typedef {import('@tetherto/wdk-wallet/protocols').IBridgeProtocol} IBridgeProtocol */

/** @typedef {import('@wdk/wallet/protocols').ILendingProtocol} ILendingProtocol */
/** @typedef {import('@tetherto/wdk-wallet/protocols').ILendingProtocol} ILendingProtocol */

/** @interface */
export class IWalletAccountWithProtocols extends IWalletAccount {
Expand Down
Loading
Loading