work on 1155 batching

enumerate
lza_menace 2 years ago
parent 197e0a4a16
commit 6f9b4000a8

@ -136,22 +136,30 @@
} }
function deriveTokenTotals(recipients, tokens) { function deriveTokenTotals(recipients, tokens) {
let totals = { const counts = {};
addresses: [], let new_addr = [];
tokenIds: [], let new_token = [];
amounts: [] let new_amount = [];
}; for (var i = 0; i < recipients.length; i++) {
for (let i = 0; i < recipients.length; i++) { let x = recipients[i] + "_" + tokens[i];
// counts[x] = (counts[x] || 0) + 1;
} }
for (const [key, value] of Object.entries(counts)) {
new_addr.push(key.split('_')[0]);
new_token.push(key.split('_')[1]);
new_amount.push(value);
}
return {new_addr, new_token, new_amount}
} }
async function estimateCBT(recipients, tokens, isERC1155) { async function estimateCBT(recipients, tokens, isERC1155) {
si_gasLimit = 0; si_gasLimit = 0;
// TODO - erc1155 batching
let fee = await $contracts.shipit.methods.usageFee().call(); let fee = await $contracts.shipit.methods.usageFee().call();
if (isERC1155) { if (isERC1155) {
let {new_addr, new_token, new_amount} = deriveTokenTotals(recipients, tokens);
await $contracts.shipit.methods.erc1155BulkTransfer(contractAddress, new_addr, new_token, new_amount).estimateGas({from: $selectedAccount, value: fee * recipients.length}, function(err, gas){
si_gasLimit += gas;
});
} else { } else {
await $contracts.shipit.methods.erc721BulkTransfer(contractAddress, recipients, tokens).estimateGas({from: $selectedAccount, value: fee * recipients.length}, function(err, gas){ await $contracts.shipit.methods.erc721BulkTransfer(contractAddress, recipients, tokens).estimateGas({from: $selectedAccount, value: fee * recipients.length}, function(err, gas){
si_gasLimit += gas; si_gasLimit += gas;
@ -161,13 +169,15 @@
async function estimateSTF(recipients, tokens, isERC1155) { async function estimateSTF(recipients, tokens, isERC1155) {
gasLimit = 0; gasLimit = 0;
// TODO - erc1155 batching if (isERC1155) {
for (let i = 0; i < recipients.length; i++) { let {new_addr, new_token, new_amount} = deriveTokenTotals(recipients, tokens);
if (isERC1155) { for (let i = 0; i < new_addr.length; i++) {
await $contracts.nft.methods.safeTransferFrom($selectedAccount, recipients[i], tokens[i], 1, "").estimateGas({from: $selectedAccount}, function(err, gas){ await $contracts.nft.methods.safeTransferFrom($selectedAccount, new_addr[i], new_token[i], new_amount[i], "").estimateGas({from: $selectedAccount}, function(err, gas){
gasLimit += gas; gasLimit += gas;
}); });
} else { }
} else {
for (let i = 0; i < recipients.length; i++) {
await $contracts.nft.methods.safeTransferFrom($selectedAccount, recipients[i], tokens[i]).estimateGas({from: $selectedAccount}, function(err, gas){ await $contracts.nft.methods.safeTransferFrom($selectedAccount, recipients[i], tokens[i]).estimateGas({from: $selectedAccount}, function(err, gas){
gasLimit += gas; gasLimit += gas;
}); });
@ -210,11 +220,11 @@
{#if $selectedAccount} {#if $selectedAccount}
<form> <form>
<div class="row"> <div class="row">
<div class="ten columns"> <div class="eight columns">
<label for="contractAddress">Contract Address</label> <label for="contractAddress">Contract Address</label>
<input class="u-full-width" type="text" placeholder="0x..." id="contractAddress" bind:value={contractAddress}> <input class="u-full-width" type="text" placeholder="0x..." id="contractAddress" bind:value={contractAddress}>
</div> </div>
<div class="two columns"> <div class="four columns">
<label for="tokenStandard">Token Standard</label> <label for="tokenStandard">Token Standard</label>
<select class="u-full-width" id="tokenStandard" bind:value={selectedStandard} on:change={clearMessages}> <select class="u-full-width" id="tokenStandard" bind:value={selectedStandard} on:change={clearMessages}>
{#each tokenStandards as s} {#each tokenStandards as s}

@ -0,0 +1,37 @@
let _addresses = [
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
'0x653d2d1d10c79017b2ea5f5a6f02d9ab6e725395',
'0x653d2d1d10c79017b2ea5f5a6f02d9ab6e725395',
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
'0x653d2d1d10c79017b2ea5f5a6f02d9ab6e725395',
'0x653d2d1d10c79017b2ea5f5a6f02d9ab6e725395',
'0x653d2d1d10c79017b2ea5f5a6f02d9ab6e725395',
'0x653d2d1d10c79017b2ea5f5a6f02d9ab6e725395',
];
let _tokens = [
1,5,3,5,1,1,2,2,2,2
];
const counts = {};
for (var i = 0; i < _addresses.length; i++) {
let x = _addresses[i] + "_" + _tokens[i];
counts[x] = (counts[x] || 0) + 1;
}
let new_addr = [];
let new_token = [];
let new_amount = [];
for (const [key, value] of Object.entries(counts)) {
new_addr.push(key.split('_')[0]);
new_token.push(key.split('_')[1]);
new_amount.push(value);
}
console.log(new_addr);
console.log(new_token);
console.log(new_amount);
Loading…
Cancel
Save