Skip to content

Commit

Permalink
Merge pull request #4284 from BitGo/WIN-1961-update-encoding
Browse files Browse the repository at this point in the history
chore(sdk-coin-zketh): fix transaction endcoding method for zksync
  • Loading branch information
mukeshsp authored Feb 16, 2024
2 parents 51bef4d + 7a3d386 commit 86873a3
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
6 changes: 6 additions & 0 deletions modules/sdk-coin-zketh/test/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export const SEND_FUNDS_SEQUENCE_ZERO_DATA =
export const SEND_FUNDS_AMOUNT_ZERO_DATA =
'0x391252150000000000000000000000007325a3f7d4f9e86ae62cf742426078c3755730d5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000005ec6ab34000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041fdfb5e9d7944ca296534feb025ad980106bf4060d5b60ff2e57cf0dfb370573975e077d4ba73e5784b9e4893e1738c88a7876313ca4d812d69b0bf9e9c4281f11b00000000000000000000000000000000000000000000000000000000000000';

export const SEND_TX_AMOUNT_ZERO_BROADCAST =
'0xf901cc02843b9aca0083b8a1a0948f977e912ef500548a0c3be6ddde9899f1199b8180b901643912521500000000000000000000000019645032c7f1533395d44a629462e751084d3e4c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000005ec67e28000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041117569462413d28fecb78b7a1472e69668018d8fe9bd8401e001cf70d594c3ac5e4ebfcc73abb9e24320853148136f4ec51b91f6559b3b87441a266c5f5f46181b0000000000000000000000000000000000000000000000000000000000000082027ba02cc25a5f192c271a3b2f36196f4fca4ba8a10526a56d31fe02a6d366b5613b9ba018e2f183c766f90070dc061aef80d9828ffbe6b80e5960f2c7ac5def2892ec8e';

export const SEND_TX_BROADCAST_LEGACY =
'0xf901cc02843b9aca0083b8a1a0948f977e912ef500548a0c3be6ddde9899f1199b8180b901643912521500000000000000000000000019645032c7f1533395d44a629462e751084d3e4c000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000005ec67e28000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000418440df6da7df3c5d6c2ae9b9fc917cfc4803ec578d0f6e39e364ed51d03e15814a1e9c97b2788111710c05a79b74ad47ff72853fddb359a3a65f29c3f57b316f1b0000000000000000000000000000000000000000000000000000000000000082027ba02c0739f514687446c88eb5fb88077abba65b96e62d5e2fe4ea6f3da103365d18a02cf04ad7a1e82541f151fc48bcf2bd8c57f1c53c1dbc6cb603363f39755e6ced';

export const SEND_ZKETH_LINK_DATA =
'0x0dcd7a6c0000000000000000000000007325a3f7d4f9e86ae62cf742426078c3755730d5000000000000000000000000000000000000000000000000016345785d8a0000000000000000000000000000cccb29bac5ad81290383643c6fb38130cda9d881000000000000000000000000000000000000000000000000000000005ec6ab34000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000041075389c62b993ab6f17cb485353135435943cea945c25b14fa0d23f71f8a51b174dd89a26174ec78e96e3d308d7d70894bea664a0366f2a42cd43e1988b50c3b1b00000000000000000000000000000000000000000000000000000000000000';

Expand Down
79 changes: 79 additions & 0 deletions modules/sdk-coin-zketh/test/unit/transactionBuilder/send.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { TransactionType } from '@bitgo/sdk-core';
import should from 'should';
import { decodeTransferData } from '@bitgo/abstract-eth';
import * as testData from '../../resources';
import { getBuilder } from '../../getBuilder';
import { TransactionBuilder } from '../../../src';

describe('ZKeth transaction builder send', () => {
describe('should sign and build', () => {
let txBuilder;
let key;
let contractAddress;

beforeEach(() => {
contractAddress = '0x8f977e912ef500548a0c3be6ddde9899f1199b81';
txBuilder = getBuilder('tzketh') as TransactionBuilder;
key = testData.KEYPAIR_PRV.getKeys().prv as string;
txBuilder.fee({
fee: '1000000000',
gasLimit: '12100000',
});
txBuilder.counter(2);
txBuilder.type(TransactionType.Send);
txBuilder.contract(contractAddress);
});

it('a send funds transaction', async () => {
const recipient = '0x19645032c7f1533395d44a629462e751084d3e4c';
const amount = '1000000000';
const expireTime = 1590066728;
const sequenceId = 5;
txBuilder
.transfer()
.amount(amount)
.to(recipient)
.expirationTime(expireTime)
.contractSequenceId(sequenceId)
.key(key);
txBuilder.sign({ key: testData.PRIVATE_KEY_1 });
const tx = await txBuilder.build();

should.equal(tx.toJson().chainId, '0x12c');
should.equal(tx.toBroadcastFormat(), testData.SEND_TX_BROADCAST_LEGACY);
should.equal(tx.signature.length, 2);
should.equal(tx.inputs.length, 1);
should.equal(tx.inputs[0].address, contractAddress);
should.equal(tx.inputs[0].value, amount);

should.equal(tx.outputs.length, 1);
should.equal(tx.outputs[0].address, recipient);
should.equal(tx.outputs[0].value, amount);

const data = tx.toJson().data;
const {
to,
amount: parsedAmount,
expireTime: parsedExpireTime,
sequenceId: parsedSequenceId,
} = decodeTransferData(data);
should.equal(to, recipient);
should.equal(parsedAmount, amount);
should.equal(parsedExpireTime, expireTime);
should.equal(parsedSequenceId, sequenceId);
});

it('a send funds with amount 0 transaction', async () => {
txBuilder
.transfer()
.amount('0')
.to('0x19645032c7f1533395d44a629462e751084d3e4c')
.expirationTime(1590066728)
.contractSequenceId(5)
.key(key);
txBuilder.sign({ key: testData.PRIVATE_KEY_1 });
const tx = await txBuilder.build();
should.equal(tx.toBroadcastFormat(), testData.SEND_TX_AMOUNT_ZERO_BROADCAST);
});
});
});
8 changes: 6 additions & 2 deletions modules/statics/src/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,12 @@ const OPETH_FEATURES = [
CoinFeature.EVM_WALLET,
CoinFeature.USES_NON_PACKED_ENCODING_FOR_TXDATA,
];
const ZKETH_FEATURES = [...ETH_FEATURES, CoinFeature.MULTISIG_COLD, CoinFeature.EVM_WALLET];

const ZKETH_FEATURES = [
...ETH_FEATURES,
CoinFeature.MULTISIG_COLD,
CoinFeature.EVM_WALLET,
CoinFeature.USES_NON_PACKED_ENCODING_FOR_TXDATA,
];
export const coins = CoinMap.fromCoins([
utxo(
'8d6e08d5-399f-414f-8430-6ceca1798cbf',
Expand Down
4 changes: 4 additions & 0 deletions modules/statics/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@ class ZkSyncTestnet extends Testnet implements EthereumNetwork {
chainId = 300;
nativeCoinOperationHashPrefix = '300';
tokenOperationHashPrefix = '300-ERC20';
forwarderFactoryAddress = '0xdd498702f44c4da08eb9e08d3f015eefe5cb71fc';
forwarderImplementationAddress = '0xbe69cae311191fb45e648ed20847f06fad2dbab4';
walletFactoryAddress = '0x4550e1e7616d3364877fc6c9324938dab678621a';
walletImplementationAddress = '0x92db2759d1dca129a0d9d46877f361be819184c4';
}

export const Networks = {
Expand Down

0 comments on commit 86873a3

Please sign in to comment.