Skip to content

Commit

Permalink
fix polygon + one gas estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Sramko committed Aug 12, 2021
1 parent 58b2e4a commit 6413372
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 47 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.19.9",
"version": "1.19.10",
"description": "",
"main": "dist/src/index.js",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
87 changes: 79 additions & 8 deletions src/nft/marketplace/listing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import {CeloProvider} from '@celo-tools/celo-ethers-wrapper'
import {bscBroadcast} from '../../blockchain'
import * as listing from '../../contracts/marketplace'
import {CeloProvider} from '@celo-tools/celo-ethers-wrapper';
import {bscBroadcast, polygonBroadcast} from '../../blockchain';
import * as listing from '../../contracts/marketplace';
import {
ApproveMarketplaceErc20Spending,
CreateMarketplaceListing,
Currency,
DeployMarketplaceListing,
InvokeMarketplaceListingOperation,
SmartContractReadMethodInvocation
} from '../../model'
} from '../../model';
import {
sendBscSmartContractMethodInvocationTransaction,
sendBscSmartContractReadMethodInvocationTransaction,
sendCeloSmartContractReadMethodInvocationTransaction
} from '../../transaction'
import {transferNFT} from '../nft'
import {deployMarketplaceListing, prepareMarketplaceApproveErc20Spending, prepareMarketplaceBuyListing, prepareMarketplaceCreateListing} from './listing'
sendCeloSmartContractReadMethodInvocationTransaction,
sendPolygonSmartContractMethodInvocationTransaction,
sendPolygonSmartContractReadMethodInvocationTransaction
} from '../../transaction';
import {transferNFT} from '../nft';
import {deployMarketplaceListing, prepareMarketplaceApproveErc20Spending, prepareMarketplaceBuyListing, prepareMarketplaceCreateListing} from './listing';

describe('Marketplace Listing tests', () => {
jest.setTimeout(99999)
Expand Down Expand Up @@ -202,4 +204,73 @@ describe('Marketplace Listing tests', () => {
})

})

describe('Marketplace Listing MATIC transactions', () => {
it('should deploy marketplace', async () => {
const body = new DeployMarketplaceListing();
body.fromPrivateKey = '0x1a4344e55c562db08700dd32e52e62e7c40b1ef5e27c6ddd969de9891a899b29';
body.feeRecipient = '0x811dfbff13adfbc3cf653dcc373c03616d3471c9';
body.marketplaceFee = 150;
body.chain = Currency.MATIC;
const test = await deployMarketplaceListing(true, body, 'https://rpc-mumbai.matic.today');
console.log(test);
expect(test).toBeDefined();
});

it('should create listing native asset', async () => {
const body = new CreateMarketplaceListing();
body.fromPrivateKey = '0x1a4344e55c562db08700dd32e52e62e7c40b1ef5e27c6ddd969de9891a899b29';
body.contractAddress = '0xe6938a3e82168e462d6250a85e78a17356af34d4';
body.nftAddress = '0x5d7d868ed584b04b922905a481f274206a42dd8a';
body.tokenId = '1626777706895';
body.listingId = '10';
body.isErc721 = true;
body.price = '0.001';
body.seller = '0x811dfbff13adfbc3cf653dcc373c03616d3471c9';
body.chain = Currency.MATIC;
const txData = await prepareMarketplaceCreateListing(true, body, 'https://rpc-mumbai.matic.today');
expect(txData).toContain('0x');
console.log(await polygonBroadcast(txData));

await new Promise(r => setTimeout(r, 5000));
console.log(await transferNFT(true, {
to: '0xe6938a3e82168e462d6250a85e78a17356af34d4',
chain: Currency.MATIC,
tokenId: '1626777706895',
fromPrivateKey: '0x1a4344e55c562db08700dd32e52e62e7c40b1ef5e27c6ddd969de9891a899b29',
contractAddress: '0x5d7d868ed584b04b922905a481f274206a42dd8a'
}));
});

it('should get listing', async () => {
const r = new SmartContractReadMethodInvocation();
r.contractAddress = '0xe6938a3e82168e462d6250a85e78a17356af34d4';
r.methodName = 'getListing';
r.methodABI = listing.abi.find(a => a.name === r.methodName);
r.params = ['8'];
console.log(await sendPolygonSmartContractMethodInvocationTransaction(true, r, 'https://rpc-mumbai.matic.today'));
});

it('should get marketplace fee', async () => {
const r = new SmartContractReadMethodInvocation();
r.contractAddress = '0xe6938a3e82168e462d6250a85e78a17356af34d4';
r.methodName = 'getMarketplaceFee';
r.methodABI = listing.abi.find(a => a.name === r.methodName);
r.params = [];
console.log(await sendPolygonSmartContractReadMethodInvocationTransaction(true, r, 'https://rpc-mumbai.matic.today'));
});

it('should buy listing native', async () => {
const body = new InvokeMarketplaceListingOperation();
body.fromPrivateKey = '0x3497eb7fa0fadf23da006c31f874a5aaed7da58c1caf3d84fa3387e1208ada39';
body.contractAddress = '0xe6938a3e82168e462d6250a85e78a17356af34d4';
body.listingId = '10';
body.amount = '0.0015';
body.chain = Currency.MATIC;
const txData = await prepareMarketplaceBuyListing(true, body, 'https://rpc-mumbai.matic.today');
expect(txData).toContain('0x');
console.log(await polygonBroadcast(txData));
});

});
})
38 changes: 19 additions & 19 deletions src/transaction/one.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {HarmonyAddress} from '@harmony-js/crypto'
import {BigNumber} from 'bignumber.js'
import Web3 from 'web3'
import {TransactionConfig} from 'web3-core'
import {toWei} from 'web3-utils'
import {oneBroadcast} from '../blockchain'
import {validateBody} from '../connector/tatum'
import {TATUM_API_URL} from '../constants'
import erc1155TokenABI from '../contracts/erc1155/erc1155_abi'
import erc1155TokenBytecode from '../contracts/erc1155/erc1155_bytecode'
import erc20_abi from '../contracts/erc20/token_abi'
import erc20TokenABI from '../contracts/erc20/token_abi'
import erc20TokenBytecode from '../contracts/erc20/token_bytecode'
import erc721TokenABI from '../contracts/erc721/erc721_abi'
import erc721TokenBytecode from '../contracts/erc721/erc721_bytecode'
import * as listing from '../contracts/marketplace'
import {HarmonyAddress} from '@harmony-js/crypto';
import {BigNumber} from 'bignumber.js';
import Web3 from 'web3';
import {TransactionConfig} from 'web3-core';
import {toWei} from 'web3-utils';
import {oneBroadcast} from '../blockchain';
import {validateBody} from '../connector/tatum';
import {TATUM_API_URL} from '../constants';
import erc1155TokenABI from '../contracts/erc1155/erc1155_abi';
import erc1155TokenBytecode from '../contracts/erc1155/erc1155_bytecode';
import erc20_abi from '../contracts/erc20/token_abi';
import erc20TokenABI from '../contracts/erc20/token_abi';
import erc20TokenBytecode from '../contracts/erc20/token_bytecode';
import erc721TokenABI from '../contracts/erc721/erc721_abi';
import erc721TokenBytecode from '../contracts/erc721/erc721_bytecode';
import * as listing from '../contracts/marketplace';
import {
CreateRecord,
Currency,
Expand All @@ -40,8 +40,8 @@ import {
SmartContractMethodInvocation,
SmartContractReadMethodInvocation,
TransactionKMS,
} from '../model'
import {obtainCustodialAddressType} from '../wallet'
} from '../model';
import {obtainCustodialAddressType} from '../wallet';

const prepareGeneralTx = async (client: Web3, testnet: boolean, fromPrivateKey?: string, signatureId?: string, to?: string, amount?: string, nonce?: number,
data?: string, gasLimit?: string, gasPrice?: string) => {
Expand All @@ -59,7 +59,7 @@ const prepareGeneralTx = async (client: Web3, testnet: boolean, fromPrivateKey?:
if (signatureId) {
return JSON.stringify(tx)
}
tx.gas = gasLimit || await client.eth.estimateGas({to: recipient, data: data || ''})
tx.gas = gasLimit || await client.eth.estimateGas({to: recipient, data: data || '', value: tx.value})
return (await client.eth.accounts.signTransaction(tx, fromPrivateKey as string)).rawTransaction as string
}

Expand Down
38 changes: 19 additions & 19 deletions src/transaction/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import axios from 'axios'
import {BigNumber} from 'bignumber.js'
import Web3 from 'web3'
import {TransactionConfig} from 'web3-core'
import {toWei} from 'web3-utils'
import {polygonBroadcast} from '../blockchain'
import {validateBody} from '../connector/tatum'
import {CONTRACT_ADDRESSES, CONTRACT_DECIMALS, TATUM_API_URL, TRANSFER_METHOD_ABI} from '../constants'
import erc1155TokenABI from '../contracts/erc1155/erc1155_abi'
import erc1155TokenBytecode from '../contracts/erc1155/erc1155_bytecode'
import erc20_abi from '../contracts/erc20/token_abi'
import erc20TokenABI from '../contracts/erc20/token_abi'
import erc20TokenBytecode from '../contracts/erc20/token_bytecode'
import erc721TokenABI from '../contracts/erc721/erc721_abi'
import erc721TokenBytecode from '../contracts/erc721/erc721_bytecode'
import * as listing from '../contracts/marketplace'
import axios from 'axios';
import {BigNumber} from 'bignumber.js';
import Web3 from 'web3';
import {TransactionConfig} from 'web3-core';
import {toWei} from 'web3-utils';
import {polygonBroadcast} from '../blockchain';
import {validateBody} from '../connector/tatum';
import {CONTRACT_ADDRESSES, CONTRACT_DECIMALS, TATUM_API_URL, TRANSFER_METHOD_ABI} from '../constants';
import erc1155TokenABI from '../contracts/erc1155/erc1155_abi';
import erc1155TokenBytecode from '../contracts/erc1155/erc1155_bytecode';
import erc20_abi from '../contracts/erc20/token_abi';
import erc20TokenABI from '../contracts/erc20/token_abi';
import erc20TokenBytecode from '../contracts/erc20/token_bytecode';
import erc721TokenABI from '../contracts/erc721/erc721_abi';
import erc721TokenBytecode from '../contracts/erc721/erc721_bytecode';
import * as listing from '../contracts/marketplace';
import {
BurnErc20,
BurnMultiToken,
Expand Down Expand Up @@ -42,8 +42,8 @@ import {
TransferMultiToken,
TransferMultiTokenBatch,
UpdateCashbackErc721,
} from '../model'
import {obtainCustodialAddressType} from '../wallet'
} from '../model';
import {obtainCustodialAddressType} from '../wallet';

/**
* Estimate Gas price for the transaction.
Expand All @@ -68,7 +68,7 @@ const prepareGeneralTx = async (client: Web3, testnet: boolean, fromPrivateKey?:
if (signatureId) {
return JSON.stringify(tx)
}
tx.gas = gasLimit || await client.eth.estimateGas({to, data: data || ''})
tx.gas = gasLimit || await client.eth.estimateGas({to, data: data || '', value: tx.value})
return (await client.eth.accounts.signTransaction(tx, fromPrivateKey as string)).rawTransaction as string
}

Expand Down

0 comments on commit 6413372

Please sign in to comment.