Skip to content

Commit

Permalink
fix transfer batch 721 from custodial wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ssramko committed Nov 23, 2021
1 parent 53ea994 commit 7118e6d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 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.17",
"version": "1.29.18",
"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
6 changes: 3 additions & 3 deletions src/model/request/TransferFromCustodialAddressBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class TransferFromCustodialAddressBatch extends PrivateKeyOrSignatureId {
@ValidateIf(o => o.contractType !== ContractType.NATIVE_ASSET)
@IsArray()
@IsNotEmpty()
public tokenAddress: string[];
public tokenAddress?: string[];

@Validate(CustodialBatchTransferValidator)
@IsArray()
Expand All @@ -36,13 +36,13 @@ export class TransferFromCustodialAddressBatch extends PrivateKeyOrSignatureId {
@ValidateIf(o => o.contractType !== ContractType.NON_FUNGIBLE_TOKEN)
@IsNotEmpty()
@IsArray()
public amount: string[];
public amount?: string[];

@ValidateIf(o => o.contractType !== ContractType.NATIVE_ASSET && o.contractType !== ContractType.FUNGIBLE_TOKEN)
@IsNotEmpty()
@Validate(CustodialBatchTransferValidator)
@IsArray()
public tokenId: string[];
public tokenId?: string[];

@IsOptional()
@Min(0)
Expand Down
6 changes: 3 additions & 3 deletions src/model/validation/CustodialBatchTransferValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export class CustodialBatchTransferValidator implements ValidatorConstraintInter
const data = validationArguments?.object as TransferFromCustodialAddressBatch
if (data.recipient.length !== data.contractType.length)
return false
if (data.recipient.length !== data.tokenAddress.length)
if (data.recipient.length !== data.tokenAddress?.length)
return false
if (data.recipient.length !== data.tokenId.length)
if (data.recipient.length !== data.tokenId?.length)
return false
return data.recipient.length === data.amount.length
return data.recipient.length === data.amount?.length

}

Expand Down
20 changes: 19 additions & 1 deletion src/wallet/custodial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
describe('Custodial wallet tests', () => {

process.env.TRON_PRO_API_KEY = 'b35409b4-7d11-491e-8760-32d2506a90b5';
jest.setTimeout(9999);
jest.setTimeout(99999);

describe('Feature enablement logic', () => {
it('should deploy all batch', () => {
Expand Down Expand Up @@ -459,6 +459,24 @@ describe('Custodial wallet tests', () => {
console.log(await bscBroadcast(txData))
})

it('should transfer 2 NFTs batch on CELO', async () => {
const body = new TransferFromCustodialAddressBatch();
body.fromPrivateKey = '0x37b091fc4ce46a56da643f021254612551dbe0944679a6e09cb5724d3085c9ab';
body.chain = Currency.CELO;
body.contractType = [ContractType.NON_FUNGIBLE_TOKEN, ContractType.NON_FUNGIBLE_TOKEN];
body.custodialAddress = '0x7d0964ec4cd1817b8ad4830122f99b258fec1102';
body.tokenAddress = ['0x4f54fAD27F7F46C102Cd49b8E75C5593397cd9c3', '0x4f54fAD27F7F46C102Cd49b8E75C5593397cd9c3'];
body.recipient = ['0x8cb76aEd9C5e336ef961265c6079C14e9cD3D2eA', '0x8cb76aEd9C5e336ef961265c6079C14e9cD3D2eA'];
body.tokenId = ['61', '62']
body.amount = ['0', '0']
const txData = await prepareBatchTransferFromCustodialWallet(true, body)
expect(txData).toContain('0x')
console.log(txData);
const provider = new CeloProvider('https://alfajores-forno.celo-testnet.org');
await provider.ready;
console.log(await provider.sendTransaction(txData));
})

})
describe('Transfer from address TRON', () => {

Expand Down
8 changes: 4 additions & 4 deletions src/wallet/custodial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,13 @@ export const prepareBatchTransferFromCustodialWallet = async (testnet: boolean,
const amounts = [];
const tokenIds = [];
for (let i = 0; i < body.contractType.length; i++) {
let amount = new BigNumber(body.amount[i]);
let tokenId = new BigNumber(body.tokenId[i]);
let amount = new BigNumber(body.amount ? body.amount[i] : 0);
let tokenId = new BigNumber(body.tokenId ? body.tokenId[i] : 0);
if (body.contractType[i] === ContractType.NATIVE_ASSET) {
amount = amount.multipliedBy(new BigNumber(10).pow(decimals));
} else if (body.contractType[i] === ContractType.NON_FUNGIBLE_TOKEN) {
amount = new BigNumber(0);
} else if (body.contractType[i] === ContractType.FUNGIBLE_TOKEN) {
} else if (body.contractType[i] === ContractType.FUNGIBLE_TOKEN && body.tokenAddress) {
tokenId = new BigNumber(0);
switch (body.chain) {
case Currency.CELO:
Expand Down Expand Up @@ -442,7 +442,7 @@ export const prepareBatchTransferFromCustodialWallet = async (testnet: boolean,
amounts.push(`0x${amount.toString(16)}`);
tokenIds.push(`0x${tokenId.toString(16)}`);
}
r.params = [body.tokenAddress.map(t => t === '0' ? '0x000000000000000000000000000000000000dEaD' : t), body.contractType, body.recipient, amounts, tokenIds];
r.params = [(body.tokenAddress || []).map(t => t === '0' ? '0x000000000000000000000000000000000000dEaD' : t), body.contractType, body.recipient, amounts, tokenIds];
r.methodABI = CustodialFullTokenWalletWithBatch.abi.find(a => a.name === 'transferBatch');
switch (body.chain) {
case Currency.CELO:
Expand Down

0 comments on commit 7118e6d

Please sign in to comment.