Skip to content

Commit

Permalink
matic multisend
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Jul 13, 2023
1 parent 325ad49 commit ddc45ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
38 changes: 28 additions & 10 deletions packages/bitcore-wallet-service/src/lib/chain/matic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ export class MaticChain extends EthChain {
*/

getBitcoreTx(txp, opts = { signed: true }) {
const { data, outputs, payProUrl, tokenAddress, multisigContractAddress, isTokenSwap } = txp;
const {
data,
outputs,
payProUrl,
tokenAddress,
multisigContractAddress,
multiSendContractAddress,
isTokenSwap
} = txp;
const isERC20 = tokenAddress && !payProUrl && !isTokenSwap;
const isMATICMULTISIG = multisigContractAddress;
const chain = isMATICMULTISIG ? 'MATICMULTISIG' : isERC20 ? 'MATICERC20' : 'MATIC';
Expand All @@ -34,15 +42,25 @@ export class MaticChain extends EthChain {
recipients[0].data = data;
}
const unsignedTxs = [];
for (let index = 0; index < recipients.length; index++) {
const rawTx = Transactions.create({
...txp,
...recipients[index],
chain,
nonce: Number(txp.nonce) + Number(index),
recipients: [recipients[index]]
});
unsignedTxs.push(rawTx);

if (multiSendContractAddress) {
let multiSendParams = {
nonce: Number(txp.nonce),
recipients,
contractAddress: multiSendContractAddress
};
unsignedTxs.push(Transactions.create({ ...txp, chain, ...multiSendParams }));
} else {
for (let index = 0; index < recipients.length; index++) {
const rawTx = Transactions.create({
...txp,
...recipients[index],
chain,
nonce: Number(txp.nonce) + Number(index),
recipients: [recipients[index]]
});
unsignedTxs.push(rawTx);
}
}

let tx = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class MATICTxProvider extends ETHTxProvider {
chainId = 80001;
break;
case 'regtest':
chainId = 1337;
chainId = 13375;
break;
default:
chainId = 137;
Expand Down

0 comments on commit ddc45ed

Please sign in to comment.