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

Feat/support conflux #21

Merged
merged 4 commits into from
May 19, 2022
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
10 changes: 10 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ export const NATIVE_CHAIN_TOKENS = [{
network: 'moonbase-alphanet',
chainId: 1287,
nativeSymbol: 'dev'
}, {
chainType: 'conflux',
network: 'conflux eSpace',
chainId: 1030,
nativeSymbol: 'cfx'
}, {
chainType: 'conflux',
network: 'conflux eSpace Testnet',
chainId: 71,
nativeSymbol: 'cfx'
}]
6 changes: 4 additions & 2 deletions src/lib/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const getDepositAddr = (info: EverpayInfo, accountChainType: ChainType): string
return info?.lockers.arweave
} else if (accountChainType === ChainType.moon) {
return info?.lockers.moon
} else if (accountChainType === ChainType.conflux) {
return info?.lockers.conflux
}
throw new Error(ERRORS.INVALID_ACCOUNT_TYPE)
}
Expand Down Expand Up @@ -46,7 +48,7 @@ export const signMessageAsync = async (config: Config, messageData: string): Pro
let sig = ''
checkSignConfig(accountChainType, config)

if ([ChainType.ethereum, ChainType.moon].includes(accountChainType)) {
if ([ChainType.ethereum, ChainType.moon, ChainType.conflux].includes(accountChainType)) {
sig = await ethereumLib.signMessageAsync(config.ethConnectedSigner as Signer, from, messageData)
} else if (accountChainType === ChainType.arweave) {
sig = await arweaveLib.signMessageAsync(config.arJWK as ArJWK, from, personalMsgHex)
Expand All @@ -66,7 +68,7 @@ export const transferAsync = async (
const to = getDepositAddr(info, config.chainType as ChainType)
const paramsMergedTo = { ...params, to }

if ([ChainType.ethereum, ChainType.moon].includes(config.chainType as ChainType)) {
if ([ChainType.ethereum, ChainType.moon, ChainType.conflux].includes(config.chainType as ChainType)) {
return await ethereumLib.transferAsync(config.ethConnectedSigner as Signer, config.chainType as ChainType, paramsMergedTo)
} else if (config.chainType as ChainType === ChainType.arweave) {
return await arweaveLib.transferAsync(config.arJWK as ArJWK, config.chainType as ChainType, paramsMergedTo)
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum ChainType {
ethereum = 'ethereum',
moon = 'moon',
arweave = 'arweave',
conflux = 'conflux'
}

export type ArJWK = JWKInterface | 'use_wallet'
Expand Down
2 changes: 1 addition & 1 deletion src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const isArweaveAddress = (address: string): boolean => {

export const isArweaveChainPSTMode = (token?: Token): boolean => {
if (token == null) return false
return !!token.chainType.includes(ChainType.arweave) && token.symbol.toUpperCase() !== 'AR'
return token.crossChainInfoList[ChainType.arweave] != null && token.symbol.toUpperCase() !== 'AR'
}

export const getAccountChainType = (from: string): ChainType => {
Expand Down
28 changes: 28 additions & 0 deletions test/deposit.conflux.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Everpay, { ChainType } from '../src/index'
import { ethWalletHasUSDT } from './constants/wallet'
import { ethers } from 'ethers'

const providerURL = 'https://evmtestnet.confluxrpc.com'
// Define Provider
const provider = new ethers.providers.StaticJsonRpcProvider(providerURL, {
chainId: 71,
name: 'Conflux eSpace (Testnet)'
})
const signer = new ethers.Wallet(ethWalletHasUSDT.privateKey, provider)

const everpay = new Everpay({
account: ethWalletHasUSDT.address,
chainType: ChainType.conflux,
ethConnectedSigner: signer,
debug: true
})

test(`check Conflux ${ethWalletHasUSDT.address} deposit cfx`, async () => {
return await everpay.deposit({
symbol: 'cfx',
amount: '0.01'
}).then(ethTx => {
console.log('ethTx', ethTx)
expect(ethTx).toBeTruthy()
})
})