Skip to content

Commit

Permalink
feat(sdk-coin-celo): support eip1559 for celo
Browse files Browse the repository at this point in the history
Ticket: COIN-2046

TICKET: COIN-2046

BREAKING CHANGE: This commit updates the hardfork of celo, which
changes the final v value and adds support to eip1559 txn
  • Loading branch information
mullapudipruthvik committed Nov 8, 2024
1 parent f4af4ae commit 819193f
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 111 deletions.
10 changes: 4 additions & 6 deletions modules/sdk-coin-celo/src/lib/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ import EthereumCommon from '@ethereumjs/common';
/**
* A Common object defining the chain and the hardfork for CELO Testnet
*/
export const testnetCommon = EthereumCommon.forCustomChain(
'mainnet', // It's a test net based on the main ethereum net
export const testnetCommon = EthereumCommon.custom(
{
name: 'alfajores',
networkId: (coins.get('tcelo').network as EthereumNetwork).chainId,
chainId: (coins.get('tcelo').network as EthereumNetwork).chainId,
},
'petersburg'
{ hardfork: 'london' }
);

/**
* A Common object defining the chain and the hardfork for CELO Mainnet
*/
export const mainnetCommon = EthereumCommon.forCustomChain(
'mainnet',
export const mainnetCommon = EthereumCommon.custom(
{
name: 'rc1',
networkId: (coins.get('celo').network as EthereumNetwork).chainId,
chainId: (coins.get('celo').network as EthereumNetwork).chainId,
},
'petersburg'
{ hardfork: 'london' }
);
22 changes: 1 addition & 21 deletions modules/sdk-coin-celo/src/lib/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import EthereumCommon from '@ethereumjs/common';
import { Transaction as EthTransaction, LegacyTxData } from '@bitgo/sdk-coin-eth';
import { CeloTransactionData } from './types';
import * as Utils from './utils';

export class Transaction extends EthTransaction {
setTransactionData(txData: LegacyTxData): void {
this._transactionData = CeloTransactionData.fromJson(txData);
this.updateFields();
}

/** @inheritdoc */
public static fromSerialized(
coinConfig: Readonly<CoinConfig>,
common: EthereumCommon,
serializedTx: string
): Transaction {
return new Transaction(coinConfig, common, Utils.deserialize(serializedTx));
}
}
export { Transaction } from '@bitgo/abstract-eth';
10 changes: 0 additions & 10 deletions modules/sdk-coin-celo/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { StakingBuilder } from './stakingBuilder';
import { StakingCall } from './stakingCall';
import { getCommon, walletSimpleByteCode } from './utils';
import { TransferBuilder } from './transferBuilder';
import { addHexPrefix } from 'ethereumjs-util';
import BigNumber from 'bignumber.js';

export class TransactionBuilder extends EthTransactionBuilder {
Expand Down Expand Up @@ -223,15 +222,6 @@ export class TransactionBuilder extends EthTransactionBuilder {
return data;
}

/**
* Get the final v value. Final v is described in EIP-155.
*
* @protected for internal use when the enableFinalVField flag is true.
*/
protected getFinalV(): string {
return addHexPrefix(this._common.chainIdBN().toString(16));
}

/**
* The value to send along with this transaction. 0 by default
*
Expand Down
26 changes: 13 additions & 13 deletions modules/sdk-coin-celo/test/resources/celo.ts

Large diffs are not rendered by default.

57 changes: 0 additions & 57 deletions modules/sdk-coin-celo/test/unit/transaction.ts

This file was deleted.

32 changes: 31 additions & 1 deletion modules/sdk-coin-celo/test/unit/transactionBuilder/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ describe('Send transaction', function () {
should.equal(txJson.from, undefined);
});

it('should build txn with eip1559', async function () {
const txBuilder = getBuilder('tcelo') as TransactionBuilder;
txBuilder.fee({
fee: '1000000000',
gasLimit: '12100000',
eip1559: {
maxFeePerGas: '7593123',
maxPriorityFeePerGas: '150',
},
});
txBuilder.counter(2);
txBuilder.type(TransactionType.Send);
txBuilder.contract('0x8f977e912ef500548a0c3be6ddde9899f1199b81');
txBuilder
.transfer()
.coin('tcusd')
.amount('1000000000')
.to('0x19645032c7f1533395d44a629462e751084d3e4c')
.expirationTime(1590066728)
.contractSequenceId(5)
.key(key);
txBuilder.sign({ key: testData.PRIVATE_KEY });
const tx = await txBuilder.build();
const txJson = tx.toJson();
should.equal(txJson.gasLimit, '12100000');
should.equal(txJson._type, 'EIP1559');
should.equal(txJson.maxFeePerGas, '7593123');
should.equal(txJson.maxPriorityFeePerGas, '150');
});

it('a send token transaction without final v', async () => {
const recipient = '0x19645032c7f1533395d44a629462e751084d3e4c';
const contractAddress = '0x8f977e912ef500548a0c3be6ddde9899f1199b81';
Expand All @@ -183,7 +213,7 @@ describe('Send transaction', function () {
.key(key);
const tx = await txBuilder.build();
const txJson = tx.toJson();
should.equal(txJson.v, '0xaef3');
should.equal(txJson.v, '0x015e09');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Celo Transaction builder for wallet initialization', () => {
should.equal(txJson.nonce, 0);
should.equal(txJson.chainId, 44787);
// Celo has disable final v and it has chain id as v value.
should.equal(txJson.v, 44787);
should.equal(txJson.v, 0x015e09);
});

it('an init transaction from an unsigned serialized one', async () => {
Expand All @@ -86,14 +86,16 @@ describe('Celo Transaction builder for wallet initialization', () => {
should.equal(newTx.toBroadcastFormat(), testData.TX_BROADCAST);
});

it('a signed init transaction from serialized with tough signature validation', async () => {
// TODO(COIN-2208): Update the txHex with correct value using london hardfork
xit('a signed init transaction from serialized with tough signature validation', async () => {
const newTxBuilder = getBuilder('tcelo') as TransactionBuilder;
newTxBuilder.from(testData.WALLET_CREATION_TX_CHECK_SIGNATURE_VALIDATION);
const newTx = await newTxBuilder.build();
should.equal(newTx.toBroadcastFormat(), testData.WALLET_CREATION_TX_CHECK_SIGNATURE_VALIDATION);
});

it('correct transaction id', async () => {
// TODO(COIN-2208): Update the txHex with correct value using london hardfork
xit('correct transaction id', async () => {
const newTxBuilder = getBuilder('tcelo') as TransactionBuilder;
newTxBuilder.from(testData.TEST_WALLET_CREATION);
const newTx = await newTxBuilder.build();
Expand Down

0 comments on commit 819193f

Please sign in to comment.