Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feecurrency fixes #2

Merged
merged 9 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
19 changes: 19 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.2/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "celo-org/web3-plugin-transaction-types" }
],

"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [],
"snapshot": {
"useCalculatedVersion": true,
"prereleaseTemplate": "{tag}-{commit}"
}
}
5 changes: 5 additions & 0 deletions .changeset/silver-mayflies-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@celo/web3-plugin-transaction-types": patch
---

Initial release
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TEST_ACCOUNT_1="0x0000000000000000000000000000000000000000000000000000000000000000"
TEST_ACCOUNT_2="0x0000000000000000000000000000000000000000000000000000000000000000"
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ jobs:
- run: rm -rf node_modules/@celo/dev-utils/node_modules
- run: bun run build
- run: bun run test
env:
TEST_ACCOUNT_1: ${{ secrets.TEST_ACCOUNT_1 }}
TEST_ACCOUNT_2: ${{ secrets.TEST_ACCOUNT_2 }}
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Release Packages

on:
push:
branches:
- main
- master
- "prerelease/*"

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Prepare or Publish
runs-on: ["self-hosted", "org", "npm-publish"]
permissions:
contents: write
id-token: write
pull-requests: write
repository-projects: write
steps:
- uses: actions/checkout@v4
- uses: foundry-rs/foundry-toolchain@v1
- uses: oven-sh/setup-bun@v2

- uses: docker://us-west1-docker.pkg.dev/devopsre/akeyless-public/akeyless-action:latest
with:
api-url: https://api.gateway.akeyless.celo-networks-dev.org
access-id: p-kf9vjzruht6l
static-secrets: '{"/static-secrets/NPM/npm-publish-token":"NPM_TOKEN"}'

- run: bun install
- run: rm -rf node_modules/@celo/dev-utils/node_modules

- uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ env.NPM_TOKEN }}
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: bun run prepublishOnly
version: |
bun x changeset version &&
bun install &&
rm -rf node_modules/@celo/dev-utils/node_modules
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
!.eslintrc.js
!jest.config.js
lib
*.tsbuildinfo.env
*.tsbuildinfo*
.env
Binary file modified bun.lockb
Binary file not shown.
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
".": "./lib/index.js"
},
"peerDependencies": {
"web3": ">= 4.0.2 < 5"
"web3": ">= 4.13.1 < 5"
},
"devDependencies": {
"@celo/dev-utils": "^0.0.5",
Expand All @@ -37,13 +37,16 @@
"eslint-plugin-jest": "^28.6.0",
"typescript": "^5.5.4",
"typescript-eslint": "^7.17.0",
"web3": "^4.11.1"
"web3": "4.13.1-dev.cc99825.0"
},
"dependencies": {
"@celo/abis": "^11.0.0",
"@celo/abis-l2": "npm:@celo/abis@12.0.0-canary.23",
"web3-eth-accounts": "^4.1.3",
"web3-utils": "^4.3.1"
"web3-eth-accounts": "4.2.2-dev.cc99825.0",
"web3-utils": "4.3.2-dev.cc99825.0"
},
"resolutions": {
"web3-eth": "4.9.1-dev.cc99825.0"
},
"patchedDependencies": {
"@celo/dev-utils@0.0.5": "patches/@celo%2Fdev-utils@0.0.5.patch"
Expand Down
20 changes: 11 additions & 9 deletions src/cip64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
toUint8Array,
txUtils,
uint8ArrayToBigInt,
unpadUint8Array,
} from "web3-eth-accounts";
import {
bytesToHex,
Expand Down Expand Up @@ -162,12 +161,20 @@ export class CIP64Transaction extends BaseTransaction<CIP64Transaction> {
);
}
public constructor(txData: CIP64Data, opts: TxOptions = {}) {
const {
chainId,
accessList,
maxFeePerGas,
maxPriorityFeePerGas,
feeCurrency,
} = txData;

super({ ...txData, type: TxTypeToPrefix.cip64 }, opts);
const { chainId, accessList, maxFeePerGas, maxPriorityFeePerGas } = txData;

this.common = this._getCommon(opts.common, chainId);
this.chainId = this.common.chainId();
this.feeCurrency = txData.feeCurrency;

this.feeCurrency = feeCurrency;

// Populate the access list fields
const accessListData = getAccessListData(accessList ?? []);
Expand All @@ -176,9 +183,6 @@ export class CIP64Transaction extends BaseTransaction<CIP64Transaction> {
// Verify the access list format.
verifyAccessList(this.accessList);

// TODO: whitelist
// verifyFeeCurrency(this.feeCurrency);

this.maxFeePerGas = uint8ArrayToBigInt(
toUint8Array(maxFeePerGas === "" ? "0x" : maxFeePerGas)
);
Expand Down Expand Up @@ -217,7 +221,6 @@ export class CIP64Transaction extends BaseTransaction<CIP64Transaction> {
}

public getDataFee(): bigint {
// TODO adjust for feeCurrency
if (
this.cache.dataFee &&
this.cache.dataFee.hardfork === this.common.hardfork()
Expand All @@ -239,7 +242,6 @@ export class CIP64Transaction extends BaseTransaction<CIP64Transaction> {
}

public getUpfrontCost(baseFee = BigInt(0)): bigint {
// TODO adjust for feeCurrency
const prio = this.maxPriorityFeePerGas;
const maxBase = this.maxFeePerGas - baseFee;
const inclusionFeePerGas = prio < maxBase ? prio : maxBase;
Expand All @@ -258,7 +260,7 @@ export class CIP64Transaction extends BaseTransaction<CIP64Transaction> {
bigIntToUnpaddedUint8Array(this.value),
this.data,
this.accessList,
unpadUint8Array(hexToBytes(this.feeCurrency)),
hexToBytes(this.feeCurrency),
this.v !== undefined
? bigIntToUnpaddedUint8Array(this.v)
: Uint8Array.from([]),
Expand Down
Loading
Loading