Skip to content

Commit

Permalink
1076 EVM Ledger Client (#1108)
Browse files Browse the repository at this point in the history
* EVM Ledger client

* ChainId from provider

* Ethereum ledger client

* BSC Ledger client

* Avalanche ledger client

* Changeset version files

* Peer dependencies removed

* Approve return type updated to string

* Changeset version files

* Approve return type updated to string

* Bug fix

* Serialize transaction clean code

* Clients renamed

* add e2e test & jest config

---------

Co-authored-by: Thorianite <100335276+Thorian1te@users.noreply.github.com>
  • Loading branch information
0xp3gasus and Thorian1te committed Apr 20, 2024
1 parent fb0b13e commit f432295
Show file tree
Hide file tree
Showing 38 changed files with 1,173 additions and 413 deletions.
7 changes: 7 additions & 0 deletions .changeset/bright-parents-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@xchainjs/xchain-ethereum': minor
'@xchainjs/xchain-avax': minor
'@xchainjs/xchain-bsc': minor
---

`signer` parameter removed from `transfer` function for the keystore client
8 changes: 8 additions & 0 deletions .changeset/four-kids-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@xchainjs/xchain-ethereum': minor
'@xchainjs/xchain-avax': minor
'@xchainjs/xchain-bsc': minor
'@xchainjs/xchain-evm': minor
---

Ledger client
6 changes: 6 additions & 0 deletions .changeset/weak-pets-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@xchainjs/xchain-evm': patch
'@xchainjs/xchain-wallet': patch
---

`approve` return type updated from `ethers.providers.TransactionResponse` to `string`
7 changes: 7 additions & 0 deletions .changeset/wet-points-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@xchainjs/xchain-ethereum': minor
'@xchainjs/xchain-avax': minor
'@xchainjs/xchain-bsc': minor
---

`signer` parameter removed from `approve` function for the keystore client
5 changes: 3 additions & 2 deletions packages/xchain-arbitrum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
"publishConfig": {
"access": "public"
},
"dependencies": {
"@xchainjs/xchain-evm": "*"
},
"devDependencies": {
"@xchainjs/xchain-client": "^0.16.2",
"@xchainjs/xchain-crypto": "^0.3.1",
"@xchainjs/xchain-evm": "^0.4.5",
"@xchainjs/xchain-util": "^0.13.3",
"@xchainjs/xchain-evm-providers": "^0.1.7",
"axios": "^1.3.6",
Expand All @@ -45,7 +47,6 @@
"peerDependencies": {
"@xchainjs/xchain-client": "^0.16.2",
"@xchainjs/xchain-crypto": "^0.3.1",
"@xchainjs/xchain-evm": "^0.4.5",
"@xchainjs/xchain-util": "^0.13.3",
"@xchainjs/xchain-evm-providers": "^0.1.7",
"axios": "^1.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/xchain-avax/__e2e__/avax-client.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApproveParams, EstimateApproveParams, IsApprovedParams } from '@xchainj
import { CovalentProvider } from '@xchainjs/xchain-evm-providers'
import { Asset, assetAmount, assetToBase, assetToString, baseAmount } from '@xchainjs/xchain-util'

import AvaxClient from '../src/client'
import AvaxClient from '../src'
import { AVAXChain, AssetAVAX, defaultAvaxParams } from '../src/const'

// import { ApproveParams, EstimateApproveParams, IsApprovedParams } from '../src/types'
Expand Down
5 changes: 3 additions & 2 deletions packages/xchain-avax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
"publishConfig": {
"access": "public"
},
"dependencies": {
"@xchainjs/xchain-evm": "*"
},
"devDependencies": {
"@xchainjs/xchain-client": "^0.16.2",
"@xchainjs/xchain-crypto": "^0.3.1",
"@xchainjs/xchain-evm": "^0.4.5",
"@xchainjs/xchain-util": "^0.13.3",
"@xchainjs/xchain-evm-providers": "^0.1.7",
"axios": "^1.3.6",
Expand All @@ -45,7 +47,6 @@
"peerDependencies": {
"@xchainjs/xchain-client": "^0.16.2",
"@xchainjs/xchain-crypto": "^0.3.1",
"@xchainjs/xchain-evm": "^0.4.5",
"@xchainjs/xchain-util": "^0.13.3",
"@xchainjs/xchain-evm-providers": "^0.1.7",
"axios": "^1.3.6",
Expand Down
13 changes: 13 additions & 0 deletions packages/xchain-avax/src/ClientKeystore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Import the Client class from '@xchainjs/xchain-evm' module
import { ClientKeystore as EVMClientKeystore } from '@xchainjs/xchain-evm'

// Import defaultAvaxParams constant from './const' file
import { defaultAvaxParams } from './const'

// Define and export the Client class as the default exportClientKeystore
export class ClientKeystore extends EVMClientKeystore {
// Constructor function that takes an optional config parameter, defaulting to defaultAvaxParams
constructor(config = defaultAvaxParams) {
super(config)
}
}
22 changes: 22 additions & 0 deletions packages/xchain-avax/src/ClientLedger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Import statements
* Importing the `Client` class from the '@xchainjs/xchain-evm' module
* Importing the `defaultEthParams` constant from the './const' file
*/
import { ClientLedger as EVMClientLedger, EVMClientParams } from '@xchainjs/xchain-evm'

/**
* Class definition for the Avalanche EVM client.
* Extends the `XchainEvmClient` class.
*/
export class ClientLedger extends EVMClientLedger {
/**
* Constructor for the Avalanche EVM client.
* @param {Object} config - Configuration object for the client (optional).
* Defaults to `defaultEthParams` if not provided.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(config: EVMClientParams & { transport: any }) {
super(config) // Call the constructor of the parent class with the provided config or the default parameters
}
}
17 changes: 0 additions & 17 deletions packages/xchain-avax/src/client.ts

This file was deleted.

7 changes: 6 additions & 1 deletion packages/xchain-avax/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Export all elements from the 'client' module
export * from './client'
import { ClientKeystore } from './ClientKeystore'

export { ClientKeystore, ClientKeystore as Client } from './ClientKeystore'
export { ClientLedger } from './ClientLedger'

// Export all elements from the 'const' module
export * from './const'

export default ClientKeystore
2 changes: 1 addition & 1 deletion packages/xchain-bsc/__e2e__/bsc-client.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AssetInfo, Balance, Network, TxType } from '@xchainjs/xchain-client'
import { ApproveParams, EstimateApproveParams, IsApprovedParams } from '@xchainjs/xchain-evm'
import { Asset, assetAmount, assetToBase, assetToString } from '@xchainjs/xchain-util'

import BscClient from '../src/client'
import BscClient from '../src'
import { AssetBSC, BSCChain, BSC_GAS_ASSET_DECIMAL, defaultBscParams } from '../src/const'

// =====Erc-20 asset=====
Expand Down
5 changes: 3 additions & 2 deletions packages/xchain-bsc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
"publishConfig": {
"access": "public"
},
"dependencies": {
"@xchainjs/xchain-evm": "*"
},
"devDependencies": {
"@xchainjs/xchain-client": "^0.16.2",
"@xchainjs/xchain-crypto": "^0.3.1",
"@xchainjs/xchain-evm": "^0.4.5",
"@xchainjs/xchain-util": "^0.13.3",
"@xchainjs/xchain-evm-providers": "^0.1.7",
"axios": "^1.3.6",
Expand All @@ -45,7 +47,6 @@
"peerDependencies": {
"@xchainjs/xchain-client": "^0.16.2",
"@xchainjs/xchain-crypto": "^0.3.1",
"@xchainjs/xchain-evm": "^0.4.5",
"@xchainjs/xchain-util": "^0.13.3",
"@xchainjs/xchain-evm-providers": "^0.1.7",
"axios": "^1.3.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* Module importing and providing a customized client for the Binance Smart Chain (BSC).
*/
import { Client as XchainEvmClient } from '@xchainjs/xchain-evm' // Importing the base client from xchain-evm library
import { ClientKeystore as EVMClientKeystore } from '@xchainjs/xchain-evm' // Importing the base client from xchain-evm library

import { defaultBscParams } from './const' // Importing default parameters for BSC

/**
* Customized BSC client extending the base XchainEvmClient.
*/
export default class Client extends XchainEvmClient {
export class ClientKeystore extends EVMClientKeystore {
/**
* Constructor for the BSC client.
*
Expand All @@ -18,8 +18,3 @@ export default class Client extends XchainEvmClient {
super(config) // Calling the constructor of the base client with the provided configuration or default parameters
}
}

/**
* Exporting the BSC client.
*/
export { Client }
22 changes: 22 additions & 0 deletions packages/xchain-bsc/src/ClientLedger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Import statements
* Importing the `Client` class from the '@xchainjs/xchain-evm' module
* Importing the `defaultEthParams` constant from the './const' file
*/
import { ClientLedger as EVMClientLedger, EVMClientParams } from '@xchainjs/xchain-evm'

/**
* Class definition for the Binance Smart Chain EVM client.
* Extends the `XchainEvmClient` class.
*/
export class ClientLedger extends EVMClientLedger {
/**
* Constructor for the Binance Smart Chain EVM client.
* @param {Object} config - Configuration object for the client (optional).
* Defaults to `defaultEthParams` if not provided.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(config: EVMClientParams & { transport: any }) {
super(config) // Call the constructor of the parent class with the provided config or the default parameters
}
}
16 changes: 10 additions & 6 deletions packages/xchain-bsc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/**
* This module re-exports the contents of the `client` and `const` modules.
* By re-exporting these modules, consumers can import all the named exports from these modules using a single import statement.
*/
export * from './client' // Re-exporting all named exports from the 'client' module
export * from './const' // Re-exporting all named exports from the 'const' module
// Export all elements from the 'client' module
import { ClientKeystore } from './ClientKeystore'

export { ClientKeystore, ClientKeystore as Client } from './ClientKeystore'
export { ClientLedger } from './ClientLedger'

// Export all elements from the 'const' module
export * from './const'

export default ClientKeystore
22 changes: 22 additions & 0 deletions packages/xchain-ethereum/__e2e__/eth-client-ledger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
// import { Network } from '@xchainjs/xchain-client'
// import { assetAmount, assetToBase } from '@xchainjs/xchain-util'

import { ClientLedger } from '../src/ClientLedger'
import { defaultEthParams } from '../src/const'

jest.setTimeout(200000)

describe('Eth Client Ledger', () => {
let ethClient: ClientLedger
beforeAll(async () => {
const transport = await TransportNodeHid.create()

ethClient = new ClientLedger({ transport, ...defaultEthParams })
})
it('get ledger address async without verification ', async () => {
const address = await ethClient.getAddressAsync()
console.log('address', address)
expect(address).toContain('0')
})
})
6 changes: 3 additions & 3 deletions packages/xchain-ethereum/__e2e__/eth-client.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Balance, FeeOption, Network, TxType } from '@xchainjs/xchain-client'
import { ApproveParams, EstimateApproveParams, IsApprovedParams, Protocol } from '@xchainjs/xchain-evm'
import { Balance, FeeOption, Network, Protocol, TxType } from '@xchainjs/xchain-client'
import { ApproveParams, EstimateApproveParams, IsApprovedParams } from '@xchainjs/xchain-evm'
import { Asset, assetAmount, assetToBase, assetToString } from '@xchainjs/xchain-util'

import Client from '../src/client'
import { Client } from '../src'
import { AssetETH, ETHChain, defaultEthParams } from '../src/const'

// =====Erc-20 asset=====
Expand Down
5 changes: 3 additions & 2 deletions packages/xchain-ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
"publishConfig": {
"access": "public"
},
"dependencies": {
"@xchainjs/xchain-evm": "*"
},
"devDependencies": {
"@xchainjs/xchain-client": "^0.16.2",
"@xchainjs/xchain-crypto": "^0.3.1",
"@xchainjs/xchain-evm": "^0.4.5",
"@xchainjs/xchain-util": "^0.13.3",
"@xchainjs/xchain-evm-providers": "^0.1.7",
"axios": "^1.3.6",
Expand All @@ -45,7 +47,6 @@
"peerDependencies": {
"@xchainjs/xchain-client": "^0.16.2",
"@xchainjs/xchain-crypto": "^0.3.1",
"@xchainjs/xchain-evm": "^0.4.5",
"@xchainjs/xchain-util": "^0.13.3",
"@xchainjs/xchain-evm-providers": "^0.1.7",
"axios": "^1.3.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@
* Importing the `Client` class from the '@xchainjs/xchain-evm' module
* Importing the `defaultEthParams` constant from the './const' file
*/
import { Client as XchainEvmClient } from '@xchainjs/xchain-evm'
import { ClientKeystore as EVMClientKeystore } from '@xchainjs/xchain-evm'

import { defaultEthParams } from './const'

/**
* Class definition for the Dogecoin EVM client.
* Class definition for the Ethereum EVM client.
* Extends the `XchainEvmClient` class.
*/
export default class Client extends XchainEvmClient {
export class ClientKeystore extends EVMClientKeystore {
/**
* Constructor for the Dogecoin EVM client.
* Constructor for the Ethereum EVM client.
* @param {Object} config - Configuration object for the client (optional).
* Defaults to `defaultEthParams` if not provided.
*/
constructor(config = defaultEthParams) {
super(config) // Call the constructor of the parent class with the provided config or the default parameters
}
}

/**
* Export statement
* Exporting the `Client` class from this file.
*/
export { Client }
22 changes: 22 additions & 0 deletions packages/xchain-ethereum/src/ClientLedger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Import statements
* Importing the `Client` class from the '@xchainjs/xchain-evm' module
* Importing the `defaultEthParams` constant from the './const' file
*/
import { ClientLedger as EVMClientLedger, EVMClientParams } from '@xchainjs/xchain-evm'

/**
* Class definition for the Ethereum EVM client.
* Extends the `XchainEvmClient` class.
*/
export class ClientLedger extends EVMClientLedger {
/**
* Constructor for the Ethereum EVM client.
* @param {Object} config - Configuration object for the client (optional).
* Defaults to `defaultEthParams` if not provided.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(config: EVMClientParams & { transport: any }) {
super(config) // Call the constructor of the parent class with the provided config or the default parameters
}
}
15 changes: 8 additions & 7 deletions packages/xchain-ethereum/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* Export all members from the 'client' module.
*/
export * from './client'
// Export all elements from the 'client' module
import { ClientKeystore } from './ClientKeystore'

/**
* Export all members from the 'const' module.
*/
export { ClientKeystore, ClientKeystore as Client } from './ClientKeystore'
export { ClientLedger } from './ClientLedger'

// Export all elements from the 'const' module
export * from './const'

export default ClientKeystore

0 comments on commit f432295

Please sign in to comment.