From 93d2969f0f51b9631f6a357b2ec50b0c9d4fee08 Mon Sep 17 00:00:00 2001 From: xaber Date: Wed, 16 Mar 2022 15:19:15 +0800 Subject: [PATCH 1/8] chore: support moonbeam --- src/constants/index.ts | 21 +++++++++++++++++++++ src/lib/ethereum.ts | 9 +++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/constants/index.ts diff --git a/src/constants/index.ts b/src/constants/index.ts new file mode 100644 index 0000000..f4415bd --- /dev/null +++ b/src/constants/index.ts @@ -0,0 +1,21 @@ +export const NATIVE_CHAIN_TOKENS = [{ + chainType: 'ethereum', + network: 'mainnet', + chainId: 1, + nativeSymbol: 'eth' +}, { + chainType: 'ethereum', + network: 'kovan', + chainId: 42, + nativeSymbol: 'eth' +}, { + chainType: 'moonbeam', + network: 'moonbeam', + chainId: 1284, + nativeSymbol: 'glmr' +}, { + chainType: 'moonbase', + network: 'moonbase', + chainId: 1287, + nativeSymbol: 'dev' +}] diff --git a/src/lib/ethereum.ts b/src/lib/ethereum.ts index 9299229..de7547d 100644 --- a/src/lib/ethereum.ts +++ b/src/lib/ethereum.ts @@ -3,6 +3,7 @@ import { TransferAsyncParams } from './interface' import erc20Abi from '../constants/abi/erc20' import { getTokenAddrByChainType } from '../utils/util' import { ChainType, EthereumTransaction } from '../types' +import { NATIVE_CHAIN_TOKENS } from '../constants' // 参考自 zkSync // https://github.com/WalletConnect/walletconnect-monorepo/issues/347#issuecomment-880553018 @@ -35,9 +36,13 @@ const transferAsync = async (ethConnectedSigner: Signer, { value }: TransferAsyncParams): Promise => { let transactionResponse: EthereumTransaction + const nativeToken = NATIVE_CHAIN_TOKENS.find(t => { + const signerNetwork = (ethConnectedSigner.provider as any)._network + return +t.chainId === +signerNetwork.chainId && t.network === signerNetwork.name + }) // TODO: check balance - if (symbol.toLowerCase() === 'eth') { + if (symbol.toLowerCase() === nativeToken?.nativeSymbol) { const transactionRequest = { from: from.toLowerCase(), to: to?.toLowerCase(), @@ -46,7 +51,7 @@ const transferAsync = async (ethConnectedSigner: Signer, { } transactionResponse = await ethConnectedSigner.sendTransaction(transactionRequest) } else { - const tokenID = getTokenAddrByChainType(token, ChainType.ethereum) + const tokenID = getTokenAddrByChainType(token, nativeToken?.chainType as ChainType) const erc20RW = new Contract(tokenID.toLowerCase(), erc20Abi, ethConnectedSigner) transactionResponse = await erc20RW.transfer(to, value, { gasLimit: 100000 From 72df8b72c56e8a19d9a99271286d7aca90e27fac Mon Sep 17 00:00:00 2001 From: xaber Date: Wed, 16 Mar 2022 16:01:12 +0800 Subject: [PATCH 2/8] chore: for moonbase test --- src/api/index.ts | 26 ++++++++++++++++++++++++++ src/constants/index.ts | 2 +- src/index.ts | 10 +++++++++- test/deposit.moonbase.test.ts | 27 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 test/deposit.moonbase.test.ts diff --git a/src/api/index.ts b/src/api/index.ts index 7b07de0..7c0f66e 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -66,6 +66,32 @@ export const getEverpayInfo = async (apiHost: string): Promise => { const result = await sendRequest({ url, method: 'GET' + }); + + // TODO: for test + (result as any).data.tokenList.push({ + tag: 'moonbase-dev-0x0000000000000000000000000000000000000000', + id: '0x0000000000000000000000000000000000000000', + symbol: 'DEV', + decimals: 18, + chainDecimals: '18', + totalSupply: '80716479282262778054', + chainType: 'moonbase-alphanet', + chainID: '42', + burnFees: { + 'moonbase-alphanet': '4160000000000000' + }, + transferFee: '0', + atomicBundleFee: '0', + holderNum: 199, + crossChainInfoList: { + 'moonbase-alphanet': { + targetChainId: '1287', + targetChainType: 'moonbase-alphanet', + targetDecimals: 18, + targetTokenId: '0x0000000000000000000000000000000000000000' + } + } }) return result.data diff --git a/src/constants/index.ts b/src/constants/index.ts index f4415bd..2b1346b 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -15,7 +15,7 @@ export const NATIVE_CHAIN_TOKENS = [{ nativeSymbol: 'glmr' }, { chainType: 'moonbase', - network: 'moonbase', + network: 'moonbase-alphanet', chainId: 1287, nativeSymbol: 'dev' }] diff --git a/src/index.ts b/src/index.ts index f4b8385..51d8e75 100644 --- a/src/index.ts +++ b/src/index.ts @@ -177,7 +177,15 @@ class Everpay extends EverpayBase { throw new Error(ERRORS.DEPOSIT_ARWEAVE_PST_MUST_BE_INTEGER) } - const chainDecimal = getChainDecimalByChainType(token, accountChainType) + let chainDecimal = 0 + + if (accountChainType === ChainType.arweave) { + chainDecimal = getChainDecimalByChainType(token, accountChainType) + } else if (accountChainType === ChainType.ethereum) { + console.log((this._config.ethConnectedSigner as any).provider._network) + chainDecimal = getChainDecimalByChainType(token, (this._config.ethConnectedSigner as any).provider._network.name) + } + const value = utils.parseUnits(toBN(amount).toString(), chainDecimal) return await transferAsync(this._config, this._cachedInfo.everpay?.value as EverpayInfo, { diff --git a/test/deposit.moonbase.test.ts b/test/deposit.moonbase.test.ts new file mode 100644 index 0000000..d1091d5 --- /dev/null +++ b/test/deposit.moonbase.test.ts @@ -0,0 +1,27 @@ +import Everpay from '../src/index' +import { ethWalletHasUSDT } from './constants/wallet' +import { ethers } from 'ethers' + +const providerURL = 'https://rpc.api.moonbase.moonbeam.network' +// Define Provider +const provider = new ethers.providers.StaticJsonRpcProvider(providerURL, { + chainId: 1287, + name: 'moonbase-alphanet' +}) +const signer = new ethers.Wallet(ethWalletHasUSDT.privateKey, provider) + +const everpay = new Everpay({ + account: ethWalletHasUSDT.address, + ethConnectedSigner: signer, + debug: true +}) + +test(`check moonbase ${ethWalletHasUSDT.address} deposit dev`, async () => { + return await everpay.deposit({ + symbol: 'dev', + amount: '0.01' + }).then(ethTx => { + console.log('ethTx', ethTx) + expect(ethTx).toBeTruthy() + }) +}) From 6fd641940a316980ca697669bcf48a4549bfa0d7 Mon Sep 17 00:00:00 2001 From: xaber Date: Wed, 16 Mar 2022 16:04:22 +0800 Subject: [PATCH 3/8] chore: add TODO comment --- src/index.ts | 1 - src/lib/sign.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 51d8e75..e8d2661 100644 --- a/src/index.ts +++ b/src/index.ts @@ -182,7 +182,6 @@ class Everpay extends EverpayBase { if (accountChainType === ChainType.arweave) { chainDecimal = getChainDecimalByChainType(token, accountChainType) } else if (accountChainType === ChainType.ethereum) { - console.log((this._config.ethConnectedSigner as any).provider._network) chainDecimal = getChainDecimalByChainType(token, (this._config.ethConnectedSigner as any).provider._network.name) } diff --git a/src/lib/sign.ts b/src/lib/sign.ts index 3f7cf81..4b5e11c 100644 --- a/src/lib/sign.ts +++ b/src/lib/sign.ts @@ -8,6 +8,7 @@ import { ERRORS } from '../utils/errors' import { getAccountChainType } from '../utils/util' import hashPersonalMessage from './hashPersonalMessage' +// TODO: moonbase locker, moonbeam locker const getDepositAddr = (info: EverpayInfo, accountChainType: ChainType): string => { if (accountChainType === ChainType.ethereum) { return info?.ethLocker From 04c643db10f5706ba1399d580fae63376da4dcdf Mon Sep 17 00:00:00 2001 From: xaber Date: Thu, 17 Mar 2022 11:31:14 +0800 Subject: [PATCH 4/8] feat: support moonbase --- src/api/index.ts | 6 +++--- src/index.ts | 16 +++++----------- src/lib/arweave.ts | 2 +- src/lib/ethereum.ts | 7 +++---- src/lib/sign.ts | 22 +++++++++++----------- src/types/index.ts | 5 ++++- test/deposit.moonbase.test.ts | 3 ++- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 2c0d367..bfa35de 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -80,15 +80,15 @@ export const getEverpayInfo = async (apiHost: string): Promise => { chainType: 'moonbase-alphanet', chainID: '42', burnFees: { - 'moonbase-alphanet': '4160000000000000' + moonbase: '4160000000000000' }, transferFee: '0', atomicBundleFee: '0', holderNum: 199, crossChainInfoList: { - 'moonbase-alphanet': { + moonbase: { targetChainId: '1287', - targetChainType: 'moonbase-alphanet', + targetChainType: 'moonbase', targetDecimals: 18, targetTokenId: '0x0000000000000000000000000000000000000000' } diff --git a/src/index.ts b/src/index.ts index e8d2661..abb965d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,8 @@ class Everpay extends EverpayBase { super() this._config = { ...config, - account: config?.account ?? '' + account: config?.account ?? '', + chainType: config?.chainType ?? ChainType.ethereum } this._apiHost = getEverpayHost(config?.debug) this._expressHost = getExpressHost(config?.debug) @@ -169,22 +170,15 @@ class Everpay extends EverpayBase { const { amount, symbol } = params const from = this._config.account const token = getTokenBySymbol(symbol, this._cachedInfo?.everpay?.value.tokenList) as Token + const chainType = this._config.chainType checkParams({ account: from, symbol, token, amount }) - const accountChainType = getAccountChainType(this._config.account as string) // arweave 上的 PST 充值必须是整数 - if (isArweaveChainPSTMode(token) && accountChainType === ChainType.arweave && parseInt(amount) !== +amount) { + if (isArweaveChainPSTMode(token) && chainType === ChainType.arweave && parseInt(amount) !== +amount) { throw new Error(ERRORS.DEPOSIT_ARWEAVE_PST_MUST_BE_INTEGER) } - let chainDecimal = 0 - - if (accountChainType === ChainType.arweave) { - chainDecimal = getChainDecimalByChainType(token, accountChainType) - } else if (accountChainType === ChainType.ethereum) { - chainDecimal = getChainDecimalByChainType(token, (this._config.ethConnectedSigner as any).provider._network.name) - } - + const chainDecimal = getChainDecimalByChainType(token, chainType as ChainType) const value = utils.parseUnits(toBN(amount).toString(), chainDecimal) return await transferAsync(this._config, this._cachedInfo.everpay?.value as EverpayInfo, { diff --git a/src/lib/arweave.ts b/src/lib/arweave.ts index 04f6c33..35a2cdc 100644 --- a/src/lib/arweave.ts +++ b/src/lib/arweave.ts @@ -99,7 +99,7 @@ const signMessageAsync = async (arJWK: ArJWK, address: string, everHash: string) return `${signatureB64url},${arOwner}` } -const transferAsync = async (arJWK: ArJWK, { +const transferAsync = async (arJWK: ArJWK, chainType: ChainType, { symbol, token, from, diff --git a/src/lib/ethereum.ts b/src/lib/ethereum.ts index de7547d..e5e24a6 100644 --- a/src/lib/ethereum.ts +++ b/src/lib/ethereum.ts @@ -28,7 +28,7 @@ const signMessageAsync = async (ethConnectedSigner: Signer, address: string, mes } } -const transferAsync = async (ethConnectedSigner: Signer, { +const transferAsync = async (ethConnectedSigner: Signer, chainType: ChainType, { symbol, token, from, @@ -37,8 +37,7 @@ const transferAsync = async (ethConnectedSigner: Signer, { }: TransferAsyncParams): Promise => { let transactionResponse: EthereumTransaction const nativeToken = NATIVE_CHAIN_TOKENS.find(t => { - const signerNetwork = (ethConnectedSigner.provider as any)._network - return +t.chainId === +signerNetwork.chainId && t.network === signerNetwork.name + return t.chainType === chainType }) // TODO: check balance @@ -51,7 +50,7 @@ const transferAsync = async (ethConnectedSigner: Signer, { } transactionResponse = await ethConnectedSigner.sendTransaction(transactionRequest) } else { - const tokenID = getTokenAddrByChainType(token, nativeToken?.chainType as ChainType) + const tokenID = getTokenAddrByChainType(token, chainType) const erc20RW = new Contract(tokenID.toLowerCase(), erc20Abi, ethConnectedSigner) transactionResponse = await erc20RW.transfer(to, value, { gasLimit: 100000 diff --git a/src/lib/sign.ts b/src/lib/sign.ts index 4b5e11c..302b51a 100644 --- a/src/lib/sign.ts +++ b/src/lib/sign.ts @@ -5,16 +5,17 @@ import { ArJWK, ChainType, Config, EverpayInfo, EverpayTxWithoutSig, EthereumTra import { checkSignConfig } from '../utils/check' import { Signer } from '@ethersproject/abstract-signer' import { ERRORS } from '../utils/errors' -import { getAccountChainType } from '../utils/util' import hashPersonalMessage from './hashPersonalMessage' -// TODO: moonbase locker, moonbeam locker const getDepositAddr = (info: EverpayInfo, accountChainType: ChainType): string => { if (accountChainType === ChainType.ethereum) { return info?.ethLocker } else if (accountChainType === ChainType.arweave) { // AR 大小写敏感 return info?.arLocker + // TODO: moonbase locker, moonbeam locker + } else if (accountChainType === ChainType.moonbase) { + return info?.ethLocker } throw new Error(ERRORS.INVALID_ACCOUNT_TYPE) } @@ -40,13 +41,13 @@ export const getEverpayTxMessage = (everpayTxWithoutSig: EverpayTxWithoutSig): s export const signMessageAsync = async (config: Config, messageData: string): Promise => { const from = config.account as string - const accountChainType = getAccountChainType(from) + const accountChainType = config.chainType as ChainType const personalMsgHashBuffer = hashPersonalMessage(Buffer.from(messageData)) const personalMsgHex = `0x${personalMsgHashBuffer.toString('hex')}` let sig = '' checkSignConfig(accountChainType, config) - if (accountChainType === ChainType.ethereum) { + if ([ChainType.ethereum, ChainType.moonbase, ChainType.moonbeam].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) @@ -61,16 +62,15 @@ export const transferAsync = async ( info: EverpayInfo, params: TransferAsyncParams ): Promise => { - const accountChainType = getAccountChainType(params.from) - checkSignConfig(accountChainType, config) + checkSignConfig(config.chainType as ChainType, config) - const to = getDepositAddr(info, accountChainType) + const to = getDepositAddr(info, config.chainType as ChainType) const paramsMergedTo = { ...params, to } - if (accountChainType === ChainType.ethereum) { - return await ethereumLib.transferAsync(config.ethConnectedSigner as Signer, paramsMergedTo) - } else if (accountChainType === ChainType.arweave) { - return await arweaveLib.transferAsync(config.arJWK as ArJWK, paramsMergedTo) + if ([ChainType.ethereum, ChainType.moonbase, ChainType.moonbeam].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) } throw new Error(ERRORS.INVALID_ACCOUNT_TYPE) diff --git a/src/types/index.ts b/src/types/index.ts index 9783bbc..1d1cf56 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,7 +6,9 @@ import { TransactionInterface as ArweaveTransaction } from 'arweave/node/lib/tra export enum ChainType { ethereum = 'ethereum', - arweave = 'arweave' + moonbase = 'moonbase', + moonbeam = 'moonbeam', + arweave = 'arweave', } export type ArJWK = JWKInterface | 'use_wallet' @@ -16,6 +18,7 @@ export { EthereumTransaction, ArweaveTransaction } export interface Config { debug?: boolean account?: string + chainType?: ChainType ethConnectedSigner?: Signer arJWK?: ArJWK } diff --git a/test/deposit.moonbase.test.ts b/test/deposit.moonbase.test.ts index d1091d5..b711636 100644 --- a/test/deposit.moonbase.test.ts +++ b/test/deposit.moonbase.test.ts @@ -1,4 +1,4 @@ -import Everpay from '../src/index' +import Everpay, { ChainType } from '../src/index' import { ethWalletHasUSDT } from './constants/wallet' import { ethers } from 'ethers' @@ -12,6 +12,7 @@ const signer = new ethers.Wallet(ethWalletHasUSDT.privateKey, provider) const everpay = new Everpay({ account: ethWalletHasUSDT.address, + chainType: ChainType.moonbase, ethConnectedSigner: signer, debug: true }) From 8ffaae8cac7e2e934edfc4cca76098c8bd1b3134 Mon Sep 17 00:00:00 2001 From: xaber Date: Thu, 17 Mar 2022 12:12:03 +0800 Subject: [PATCH 5/8] chore: update test code --- src/api/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/index.ts b/src/api/index.ts index bfa35de..9bae2d6 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -77,7 +77,7 @@ export const getEverpayInfo = async (apiHost: string): Promise => { decimals: 18, chainDecimals: '18', totalSupply: '80716479282262778054', - chainType: 'moonbase-alphanet', + chainType: 'moonbase', chainID: '42', burnFees: { moonbase: '4160000000000000' From d4d0c855b436dcbfee4be68a6cab2e2d5d67baa2 Mon Sep 17 00:00:00 2001 From: xaber Date: Wed, 6 Apr 2022 14:58:06 +0800 Subject: [PATCH 6/8] feat: add signedEverpayTx api --- package.json | 2 +- src/index.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 002a6df..f0e6bf2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "everpay", - "version": "0.4.0", + "version": "0.4.1", "main": "./cjs/index.js", "module": "./esm/index.js", "files": [ diff --git a/src/index.ts b/src/index.ts index f4b8385..badadad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,7 @@ import { Config, EverpayInfo, EverpayBase, BalanceParams, BalancesParams, DepositParams, SwapInfo, SendEverpayTxResult, TransferParams, WithdrawParams, EverpayTxWithoutSig, EverpayAction, BundleData, SwapOrder, SwapPriceParams, SwapPriceResult, FeeItem, ChainType, - BalanceItem, TxsParams, TxsByAccountParams, TxsResult, EverpayTransaction, Token, EthereumTransaction, ArweaveTransaction, ExpressInfo, CachedInfo, InternalTransferItem, BundleDataWithSigs, BundleParams + BalanceItem, TxsParams, TxsByAccountParams, TxsResult, EverpayTransaction, Token, EthereumTransaction, ArweaveTransaction, ExpressInfo, CachedInfo, InternalTransferItem, BundleDataWithSigs, BundleParams, EverpayTx } from './types' import { swapParamsClientToServer, swapParamsServerToClient } from './utils/swap' @@ -305,13 +305,18 @@ class Everpay extends EverpayBase { return getEverpayTxMessage(everpayTxWithoutSig) } - async sendEverpayTx (everpayTxWithoutSig: EverpayTxWithoutSig): Promise { + async signedEverpayTx (everpayTxWithoutSig: EverpayTxWithoutSig): Promise<{everpayTx: EverpayTx, everHash: string}> { const messageData = getEverpayTxMessage(everpayTxWithoutSig) - const { everHash, sig } = await signMessageAsync(this._config, messageData) + const { sig, everHash } = await signMessageAsync(this._config, messageData) const everpayTx = { ...everpayTxWithoutSig, sig } + return { everpayTx, everHash } + } + + async sendEverpayTx (everpayTxWithoutSig: EverpayTxWithoutSig): Promise { + const { everpayTx, everHash } = await this.signedEverpayTx(everpayTxWithoutSig) const postEverpayTxResult = await postTx(this._apiHost, everpayTx) return { ...postEverpayTxResult, From 96d545e7ae0c1af0aaa5966d9f21b478f40b05a5 Mon Sep 17 00:00:00 2001 From: xaber Date: Tue, 12 Apr 2022 14:45:31 +0800 Subject: [PATCH 7/8] feat: support moonbeam & moonbase --- src/api/index.ts | 26 -------------------------- src/constants/index.ts | 4 ++-- src/lib/sign.ts | 13 ++++++------- src/types/index.ts | 8 ++++---- test/deposit.moonbase.test.ts | 2 +- 5 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 9bae2d6..a01da7e 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -67,32 +67,6 @@ export const getEverpayInfo = async (apiHost: string): Promise => { const result = await sendRequest({ url, method: 'GET' - }); - - // TODO: for test - (result as any).data.tokenList.push({ - tag: 'moonbase-dev-0x0000000000000000000000000000000000000000', - id: '0x0000000000000000000000000000000000000000', - symbol: 'DEV', - decimals: 18, - chainDecimals: '18', - totalSupply: '80716479282262778054', - chainType: 'moonbase', - chainID: '42', - burnFees: { - moonbase: '4160000000000000' - }, - transferFee: '0', - atomicBundleFee: '0', - holderNum: 199, - crossChainInfoList: { - moonbase: { - targetChainId: '1287', - targetChainType: 'moonbase', - targetDecimals: 18, - targetTokenId: '0x0000000000000000000000000000000000000000' - } - } }) return result.data diff --git a/src/constants/index.ts b/src/constants/index.ts index 2b1346b..827a4f9 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -9,12 +9,12 @@ export const NATIVE_CHAIN_TOKENS = [{ chainId: 42, nativeSymbol: 'eth' }, { - chainType: 'moonbeam', + chainType: 'moon', network: 'moonbeam', chainId: 1284, nativeSymbol: 'glmr' }, { - chainType: 'moonbase', + chainType: 'moon', network: 'moonbase-alphanet', chainId: 1287, nativeSymbol: 'dev' diff --git a/src/lib/sign.ts b/src/lib/sign.ts index 302b51a..0f6c9bf 100644 --- a/src/lib/sign.ts +++ b/src/lib/sign.ts @@ -9,13 +9,12 @@ import hashPersonalMessage from './hashPersonalMessage' const getDepositAddr = (info: EverpayInfo, accountChainType: ChainType): string => { if (accountChainType === ChainType.ethereum) { - return info?.ethLocker + return info?.lockers.ethereum } else if (accountChainType === ChainType.arweave) { // AR 大小写敏感 - return info?.arLocker - // TODO: moonbase locker, moonbeam locker - } else if (accountChainType === ChainType.moonbase) { - return info?.ethLocker + return info?.lockers.arweave + } else if (accountChainType === ChainType.moon) { + return info?.lockers.moon } throw new Error(ERRORS.INVALID_ACCOUNT_TYPE) } @@ -47,7 +46,7 @@ export const signMessageAsync = async (config: Config, messageData: string): Pro let sig = '' checkSignConfig(accountChainType, config) - if ([ChainType.ethereum, ChainType.moonbase, ChainType.moonbeam].includes(accountChainType)) { + if ([ChainType.ethereum, ChainType.moon].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) @@ -67,7 +66,7 @@ export const transferAsync = async ( const to = getDepositAddr(info, config.chainType as ChainType) const paramsMergedTo = { ...params, to } - if ([ChainType.ethereum, ChainType.moonbase, ChainType.moonbeam].includes(config.chainType as ChainType)) { + if ([ChainType.ethereum, ChainType.moon].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) diff --git a/src/types/index.ts b/src/types/index.ts index 1d1cf56..3f03d84 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,8 +6,7 @@ import { TransactionInterface as ArweaveTransaction } from 'arweave/node/lib/tra export enum ChainType { ethereum = 'ethereum', - moonbase = 'moonbase', - moonbeam = 'moonbeam', + moon = 'moon', arweave = 'arweave', } @@ -54,8 +53,9 @@ export interface FeeItem { } export interface EverpayInfo { - ethLocker: string - arLocker: string + lockers: { + [propName: string]: string + } ethChainID: string feeRecipient: string owner: string diff --git a/test/deposit.moonbase.test.ts b/test/deposit.moonbase.test.ts index b711636..93e15e5 100644 --- a/test/deposit.moonbase.test.ts +++ b/test/deposit.moonbase.test.ts @@ -12,7 +12,7 @@ const signer = new ethers.Wallet(ethWalletHasUSDT.privateKey, provider) const everpay = new Everpay({ account: ethWalletHasUSDT.address, - chainType: ChainType.moonbase, + chainType: ChainType.moon, ethConnectedSigner: signer, debug: true }) From 738c1ab237e91417481da4a8a3045a9b6de5cf0a Mon Sep 17 00:00:00 2001 From: xaber Date: Tue, 12 Apr 2022 15:09:56 +0800 Subject: [PATCH 8/8] fix: native token deposit --- src/lib/ethereum.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/ethereum.ts b/src/lib/ethereum.ts index e5e24a6..6762c6c 100644 --- a/src/lib/ethereum.ts +++ b/src/lib/ethereum.ts @@ -36,12 +36,12 @@ const transferAsync = async (ethConnectedSigner: Signer, chainType: ChainType, { value }: TransferAsyncParams): Promise => { let transactionResponse: EthereumTransaction - const nativeToken = NATIVE_CHAIN_TOKENS.find(t => { - return t.chainType === chainType + const foundNative = NATIVE_CHAIN_TOKENS.find(t => { + return t.chainType === chainType && t.nativeSymbol === symbol.toLowerCase() }) // TODO: check balance - if (symbol.toLowerCase() === nativeToken?.nativeSymbol) { + if (foundNative != null) { const transactionRequest = { from: from.toLowerCase(), to: to?.toLowerCase(),