Skip to content

Commit

Permalink
add support for XDC and ONE for custodial wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
ssramko committed Dec 16, 2021
1 parent fff7e8d commit 3412af3
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "1.29.33",
"version": "1.30.0",
"description": "Tatum API client allows browsers and Node.js clients to interact with Tatum API.",
"main": "dist/src/index.js",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
10 changes: 8 additions & 2 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
preparePolygonClient,
preparePolygonSmartContractWriteMethodInvocation,
prepareSmartContractWriteMethodInvocation,
prepareTronSmartContractInvocation
prepareTronSmartContractInvocation,
prepareXdcSmartContractWriteMethodInvocation
} from '../transaction';

export const helperBroadcastTx = async (chain: Currency, txData: string, signatureId?: string) => {
Expand Down Expand Up @@ -77,9 +78,14 @@ export const helperPrepareSCCall = async (testnet: boolean, body: any, clazz: Cl
r.methodABI = abi.find(a => a.name === r.methodName);
switch (body.chain) {
case Currency.CELO:
return await prepareCeloSmartContractWriteMethodInvocation(testnet, {...r, feeCurrency: body.feeCurrency || Currency.CELO}, provider);
return await prepareCeloSmartContractWriteMethodInvocation(testnet, {
...r,
feeCurrency: body.feeCurrency || Currency.CELO
}, provider);
case Currency.ONE:
return await prepareOneSmartContractWriteMethodInvocation(testnet, r, provider);
case Currency.XDC:
return await prepareXdcSmartContractWriteMethodInvocation(r, provider);
case Currency.ETH:
return await prepareSmartContractWriteMethodInvocation(r, provider);
case Currency.BSC:
Expand Down
2 changes: 1 addition & 1 deletion src/model/request/ApproveCustodialTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ApproveCustodialTransfer extends PrivateKeyOrSignatureId {
public custodialAddress: string;

@IsNotEmpty()
@IsIn([Currency.ETH, Currency.MATIC, Currency.BSC, Currency.ONE, Currency.CELO])
@IsIn([Currency.ETH, Currency.MATIC, Currency.BSC, Currency.ONE, Currency.CELO, Currency.XDC])
public chain: Currency;

@IsIn([ContractType.NON_FUNGIBLE_TOKEN, ContractType.SEMI_FUNGIBLE_TOKEN, ContractType.FUNGIBLE_TOKEN])
Expand Down
2 changes: 1 addition & 1 deletion src/model/request/GenerateCustodialAddressBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {PrivateKeyOrSignatureId} from './PrivateKeyOrSignatureId';
export class GenerateCustodialAddressBatch extends PrivateKeyOrSignatureId {

@IsNotEmpty()
@IsIn([Currency.MATIC, Currency.CELO, Currency.BSC, Currency.ETH, Currency.TRON])
@IsIn([Currency.MATIC, Currency.CELO, Currency.BSC, Currency.ETH, Currency.TRON, Currency.ONE, Currency.XDC])
public chain: Currency;

@IsNumber()
Expand Down
2 changes: 1 addition & 1 deletion src/model/request/TransferFromCustodialAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class TransferFromCustodialAddress extends PrivateKeyOrSignatureId {
public custodialAddress: string;

@IsNotEmpty()
@IsIn([Currency.ETH, Currency.MATIC, Currency.BSC, Currency.ONE, Currency.CELO, Currency.TRON])
@IsIn([Currency.ETH, Currency.MATIC, Currency.BSC, Currency.ONE, Currency.CELO, Currency.TRON, Currency.XDC])
public chain: Currency;

@ValidateIf(o => o.contractType !== ContractType.NATIVE_ASSET)
Expand Down
2 changes: 1 addition & 1 deletion src/model/request/TransferFromCustodialAddressBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class TransferFromCustodialAddressBatch extends PrivateKeyOrSignatureId {
public custodialAddress: string;

@IsNotEmpty()
@IsIn([Currency.ETH, Currency.MATIC, Currency.BSC, Currency.ONE, Currency.CELO, Currency.TRON])
@IsIn([Currency.ETH, Currency.MATIC, Currency.BSC, Currency.ONE, Currency.CELO, Currency.TRON, Currency.XDC])
public chain: Currency;

@Validate(CustodialBatchTransferValidator)
Expand Down
7 changes: 6 additions & 1 deletion src/transaction/xdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export const fromXdcAddress = (xdcAddress: string): string => {
export const xdcGetGasPriceInWei = async () => {
const gasStationUrl = 'https://rpc.xinfin.network/'
try {
const {data} = await axios.post(`${gasStationUrl}gasPrice`, {'jsonrpc': '2.0', 'method': 'eth_gasPrice', 'params': [], 'id': 1})
const {data} = await axios.post(`${gasStationUrl}gasPrice`, {
'jsonrpc': '2.0',
'method': 'eth_gasPrice',
'params': [],
'id': 1
})
return data ? Web3.utils.toWei(data, 'wei') : Web3.utils.toWei('5', 'kwei')
} catch (e) {
return Web3.utils.toWei('5', 'kwei')
Expand Down
30 changes: 29 additions & 1 deletion src/wallet/custodial.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import BigNumber from 'bignumber.js';
import {bscBroadcast, celoBroadcast, ethBroadcast, polygonBroadcast, tronBroadcast} from '../blockchain';
import {
bscBroadcast,
celoBroadcast,
ethBroadcast,
oneBroadcast,
polygonBroadcast,
tronBroadcast,
xdcBroadcast
} from '../blockchain';
import {get, validateBody} from '../connector/tatum';
import {CUSTODIAL_PROXY_ABI} from '../constants';
import {
Expand Down Expand Up @@ -55,6 +63,7 @@ import {
prepareTronCustodialTransferBatch,
prepareTronGenerateCustodialWalletSignedTransaction,
prepareTronSmartContractInvocation,
prepareXdcSmartContractWriteMethodInvocation,
sendBscGenerateCustodialWalletSignedTransaction,
sendCeloGenerateCustodialWalletSignedTransaction,
sendEthGenerateCustodialWalletSignedTransaction,
Expand Down Expand Up @@ -123,6 +132,10 @@ const getCustodialFactoryContractAddress = (chain: Currency, testnet: boolean) =
return testnet ? '0x481D6f967B120E094D3551DA2C4951242Be582af' : '0x014a09b194A2Ed928aB777E83E2F27BbAc9529D0';
case Currency.TRON:
return testnet ? 'TRM8P5gpzAr85p2a5BMvqb9UfEdFEwEgA7' : 'TG59uLNQvCR45F6yKHPXipvCu7wg5D88Wr';
case Currency.ONE:
return testnet ? '0xb1462fE8E9Cf82c0296022Cca7bEfA3Fd4c12B34' : '0x6d3C42602DDf00B5E40bD810aA2075815Dae5D4D';
case Currency.XDC:
return testnet ? 'xdc6709Bdda623aF7EB152cB2fE2562aB7e031e564f' : 'xdc6709Bdda623aF7EB152cB2fE2562aB7e031e564f';
case Currency.ETH:
return testnet ? (process.env.TESTNET_TYPE === 'ethereum-rinkeby' ? '0x4eC40a4A0dA042d46cC4529f918080957003b531' : '0x3485fdba44736859267789ac9c248cc4c1443956') : '0x4cb7933f595cb081804f8078f7fe7eff717bdc4b';
case Currency.MATIC:
Expand Down Expand Up @@ -212,6 +225,10 @@ export const generateCustodialWalletBatch = async (testnet: boolean, body: Gener
return await ethBroadcast(txData, body.signatureId);
case Currency.MATIC:
return await polygonBroadcast(txData, body.signatureId);
case Currency.ONE:
return await oneBroadcast(txData, body.signatureId);
case Currency.XDC:
return await xdcBroadcast(txData, body.signatureId);
case Currency.BSC:
return await bscBroadcast(txData, body.signatureId);
default:
Expand Down Expand Up @@ -243,6 +260,7 @@ export const prepareCustodialWalletBatch = async (testnet: boolean, body: Genera
};

/**
* @Deprecated, use generateCustodialWalletBatch
* Generate new smart contract based custodial wallet. This wallet is able to receive any type of assets, but transaction costs connected to the withdrawal
* of assets is covered by the deployer.
* @param testnet chain to work with
Expand Down Expand Up @@ -319,6 +337,9 @@ export const prepareTransferFromCustodialWallet = async (testnet: boolean, body:
case Currency.ONE:
amount = amount.multipliedBy(new BigNumber(10).pow(await getOne20ContractDecimals(testnet, body.tokenAddress, provider)));
break;
case Currency.XDC:
amount = amount.multipliedBy(new BigNumber(10).pow(await getErc20Decimals(testnet, Currency.XDC, body.tokenAddress, provider)));
break;
case Currency.ETH:
amount = amount.multipliedBy(new BigNumber(10).pow(await getEthErc20ContractDecimals(testnet, body.tokenAddress, provider)));
break;
Expand All @@ -345,6 +366,8 @@ export const prepareTransferFromCustodialWallet = async (testnet: boolean, body:
}, provider);
case Currency.ONE:
return await prepareOneSmartContractWriteMethodInvocation(testnet, r, provider);
case Currency.XDC:
return await prepareXdcSmartContractWriteMethodInvocation(r, provider);
case Currency.ETH:
return await prepareSmartContractWriteMethodInvocation(r, provider);
case Currency.BSC:
Expand Down Expand Up @@ -426,6 +449,9 @@ export const prepareBatchTransferFromCustodialWallet = async (testnet: boolean,
case Currency.ONE:
amount = amount.multipliedBy(new BigNumber(10).pow(await getOne20ContractDecimals(testnet, body.tokenAddress[i], provider)));
break;
case Currency.XDC:
amount = amount.multipliedBy(new BigNumber(10).pow(await getErc20Decimals(testnet, Currency.XDC, body.tokenAddress[i], provider)));
break;
case Currency.ETH:
amount = amount.multipliedBy(new BigNumber(10).pow(await getEthErc20ContractDecimals(testnet, body.tokenAddress[i], provider)));
break;
Expand Down Expand Up @@ -455,6 +481,8 @@ export const prepareBatchTransferFromCustodialWallet = async (testnet: boolean,
}, provider);
case Currency.ONE:
return await prepareOneSmartContractWriteMethodInvocation(testnet, r, provider);
case Currency.XDC:
return await prepareXdcSmartContractWriteMethodInvocation(r, provider);
case Currency.ETH:
return await prepareSmartContractWriteMethodInvocation(r, provider);
case Currency.BSC:
Expand Down

0 comments on commit 3412af3

Please sign in to comment.