Skip to content

Commit

Permalink
Fix Script for publishing @celo/abis + @celo/contracts
Browse files Browse the repository at this point in the history
* use @celo/abis in contractkit and cli 
* offer esm and cjs imports
* remove ethers foldeer (just use plain ts files)
  • Loading branch information
shazarre authored Dec 8, 2023
1 parent 53c9529 commit 1c9c844
Show file tree
Hide file tree
Showing 82 changed files with 1,082 additions and 278 deletions.
10 changes: 10 additions & 0 deletions .changeset/cool-waves-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@celo/contractkit': major
---

Remove contracts from lib/generated. now available in @celo/abis package at @celo/abis/web3

If you were directly importing contracts from `@celo/contractkit/lib/generated/*` eg `@celo/lib/generated/Accounts` do a find replace

find: `@celo/contractkit/lib/generated/`
replace: `@celo/abis/web3/`
2 changes: 1 addition & 1 deletion .github/workflows/celo-monorepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
- name: Get the artifacts to cache
id: get_artifacts_to_cache
run: |
artifacts_to_cache="$(git ls-files --others --ignored --exclude-standard | grep -v node_modules)"
artifacts_to_cache="$(git ls-files --others --ignored --exclude-standard | grep -v node_modules | grep -v .js.map)"
echo "artifacts_to_cache<<EOF" >> $GITHUB_OUTPUT
echo "$artifacts_to_cache" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
Expand Down
24 changes: 15 additions & 9 deletions .github/workflows/publish-contracts-abi-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ jobs:
contents: write
id-token: write
pull-requests: write
repository-projects: write
repository-projects: write
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Akeyless Get Secrets
id: get_auth_token
uses: docker://us-west1-docker.pkg.dev/devopsre/akeyless-public/akeyless-action:latest
Expand All @@ -47,16 +49,16 @@ jobs:
shell: bash
run: yarn

- name: 'Build all packages'
run: yarn build

- name: Check if a release should be published
# This is what sets the RELEASE_TYPE and RELEASE_VERSION env variables
run: yarn --silent is_contract_release >> "$GITHUB_ENV"
working-directory: packages/protocol
env:
GITHUB_TAG: ${{ github.ref_name }}
INPUT_VERSION: ${{ inputs.npm_version }}

- name: 'Build packages which will not need abis'
shell: bash
run: yarn build --ignore @celo/contractkit --ignore @celo/explorer --ignore @celo/celocli --ignore @celo/governance --ignore @celo/metadata-crawler --ignore @celo/celotool --ignore @celo/env-tests --ignore @celo/transactions-uri --ignore @celo/wallet-rpc --include-dependencies
- name: Compile solidity contracts and typescript files
run: yarn prepare_contracts_and_abis_publishing
working-directory: packages/protocol
Expand All @@ -65,19 +67,23 @@ jobs:
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}

- name: Publish @celo/contracts
run: npm publish $RELEASE_TYPE $DRY_RUN
run: |
cat package.json
npm publish $RELEASE_TYPE $DRY_RUN
working-directory: packages/protocol/contracts
env:
RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag $RELEASE_TYPE' || '' }}
RELEASE_TYPE: --tag ${{ env.RELEASE_TYPE != '' && env.RELEASE_TYPE || 'canary' }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }}
DRY_RUN: ${{ env.RELEASE_VERSION == '' && '--dry-run' || '' }}

- name: Publish @celo/abis
run: npm publish $RELEASE_TYPE $DRY_RUN
run: |
cat package.json
npm publish $RELEASE_TYPE $DRY_RUN
working-directory: packages/protocol/abis
env:
RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag $RELEASE_TYPE' || '' }}
RELEASE_TYPE: --tag ${{ env.RELEASE_TYPE != '' && env.RELEASE_TYPE || 'canary' }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }}
DRY_RUN: ${{ env.RELEASE_VERSION == '' && '--dry-run' || '' }}
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ packages/protocol/scripts/**/*.js
packages/protocol/migrations/**/*.js
packages/protocol/test/**/*.js
packages/protocol/contractPackages.js

packages/protocol/abis/src-generated/

# prettier eats Latex underscore escapting and doesn't seem to have an option to disable
packages/docs/celo-codebase/protocol/proof-of-stake/epoch-rewards.md
Expand Down
7 changes: 3 additions & 4 deletions packages/celotool/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"outDir": "lib",
"rootDir": "src",
"baseUrl": ".",
"lib": ["es7", "es2017"],
"target": "es6",
"lib": ["es7", "es2017", "es2020"],
"target": "es2020",
"resolveJsonModule": true,
"esModuleInterop": true,
"paths": {
"@google-cloud/monitoring": ["types/monitoring"]
}
},
"include": ["src", "../contractkit/types"],
"include": ["src"],
"exclude": ["node_modules/"],
"references": [{ "path": "../sdk/utils" }, { "path": "../sdk/contractkit" }]
}
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"test": "TZ=UTC jest --runInBand"
},
"dependencies": {
"@celo/abis": "10.0.0",
"@celo/base": "^6.0.0",
"@celo/celo-devchain": "^6.0.3-beta.1",
"@celo/connect": "^5.1.1",
"@celo/contractkit": "^5.2.1",
"@celo/explorer": "^5.0.6",
Expand Down Expand Up @@ -73,6 +73,7 @@
"web3": "1.10.0"
},
"devDependencies": {
"@celo/celo-devchain": "^6.0.3",
"@celo/dev-utils": "0.0.1",
"@oclif/dev-cli": "^1.23.0",
"@types/cli-table": "^0.3.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export abstract class BaseCommand extends Command {
// For commands that don't require the node is synced, add the following line
// to its definition:
// requireSynced = false
public requireSynced: boolean = true
public requireSynced = true

private _web3: Web3 | null = null
private _kit: ContractKit | null = null
Expand Down Expand Up @@ -154,7 +154,10 @@ export abstract class BaseCommand extends Command {
let transport
try {
// Importing for ledger uses only fixes running jest tests
const TransportNodeHid = (await import('@ledgerhq/hw-transport-node-hid')).default
const _TransportNodeHid = (await import('@ledgerhq/hw-transport-node-hid')).default
// types seem to be suggesting 2 defaults but js is otherwise for TransportNodeHid
const TransportNodeHid: typeof _TransportNodeHid.default =
_TransportNodeHid.default || _TransportNodeHid
transport = await TransportNodeHid.open('')
const derivationPathIndexes = res.raw.some(
(value) => (value as any).flag === 'ledgerCustomAddresses'
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/network/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { newICeloVersionedContract } from '@celo/abis/web3/ICeloVersionedContract'
import { newProxy } from '@celo/abis/web3/Proxy'
import { concurrentMap } from '@celo/base'
import { CeloContract } from '@celo/contractkit'
import { newICeloVersionedContract } from '@celo/contractkit/lib/generated/ICeloVersionedContract'
import { newProxy } from '@celo/contractkit/lib/generated/Proxy'
import { cli } from 'cli-ux'
import { table } from 'cli-ux/lib/styled/table'
import { BaseCommand } from '../../base'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/releasegold/admin-revoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { newReleaseGold } from '@celo/abis/web3/ReleaseGold'
import { serializeSignature } from '@celo/base/lib/signatureUtils'
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit'
import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold'
import { AccountsWrapper } from '@celo/contractkit/lib/wrappers/Accounts'
import { GovernanceWrapper } from '@celo/contractkit/lib/wrappers/Governance'
import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newReleaseGold } from '@celo/abis/web3/ReleaseGold'
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit'
import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold'
import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold'
import { getContractFromEvent, testWithGanache } from '@celo/dev-utils/lib/ganache-test'
import Web3 from 'web3'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newReleaseGold } from '@celo/abis/web3/ReleaseGold'
import { newKitFromWeb3 } from '@celo/contractkit'
import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold'
import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold'
import { getContractFromEvent, testWithGanache } from '@celo/dev-utils/lib/ganache-test'
import Web3 from 'web3'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/releasegold/withdraw.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newReleaseGold } from '@celo/abis/web3/ReleaseGold'
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit'
import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold'
import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold'
import { getContractFromEvent, testWithGanache, timeTravel } from '@celo/dev-utils/lib/ganache-test'
import { BigNumber } from 'bignumber.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/transfer/erc20.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IERC20 } from '@celo/contractkit/lib/generated/IERC20'
import { IERC20 } from '@celo/abis/web3/IERC20'
import { Erc20Wrapper } from '@celo/contractkit/lib/wrappers/Erc20Wrapper'
import { flags } from '@oclif/command'
import BigNumber from 'bignumber.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/release-gold-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold'
import { newReleaseGold } from '@celo/abis/web3/ReleaseGold'
import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold'
import { ParserOutput } from '@oclif/parser/lib/parse'
import { BaseCommand } from '../base'
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"extends": "@celo/typescript/tsconfig.library.json",
"compilerOptions": {
"moduleResolution": "node16",
"rootDir": "src",
"outDir": "lib",
"esModuleInterop": true,
"target": "es6"
"target": "es2020"
},
"include": ["src", "../contractkit/types"],
"references": [{ "path": "../sdk/utils" }, { "path": "../sdk/contractkit" }]
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ wagmi.config.js
wagmi.config.js.map

abis/src-generated/
abis/lib/
abis/lib/
# these are copied from contracts-08 folder for purposes of publishing to npm
contracts/0.8
30 changes: 22 additions & 8 deletions packages/protocol/abis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,33 @@ yarn add @celo/abis
### In your javascript or ts

```ts
// json abi
import Accounts from '@celo/abis/Accounts.json'
// abi in json
import AccountsABI from '@celo/abis/Accounts.json'

// ethers
import { Accounts } from '@celo/abis/types/ethers'
// abi in js/ts for viem, wagmi, etc
import { accountsABI } from '@celo/abis'

// web3
import Accounts from '@celo/abis/types/web3/Accounts'
// abi in js/ts for viem, wagmi, etc (with moduleResolution and module set to "Node16" in your tsconfig.json file)
import { accountsABI } from '@celo/abis/Accounts'

// truffle
import { AccountsContract } from '@celo/abis/types/truffle'
// abi in js/ts for use with contractkit
import { type Accounts, newAccounts, ABI } from '@celo/abis/web3/Accounts'
```

### CommonJS syntax

```js
const { accountsABI } = require('@celo/abis');

// viem
const accounts = getContract({
address: "0x...",
abi: accountsABI,
...
})
```


## License

All packages are licensed under the terms of the Apache 2.0 License unless otherwise specified in the LICENSE file at package's root.
3 changes: 3 additions & 0 deletions packages/protocol/abis/package-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 3 additions & 0 deletions packages/protocol/abis/package-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Loading

0 comments on commit 1c9c844

Please sign in to comment.