Skip to content

Commit 0ac1983

Browse files
authored
Merge pull request #12 from smartcontractkit/zp-patches
Fix to Issue#8 - Viem Bug from misdocumented Viem.writeContract()
2 parents 8512a72 + d961509 commit 0ac1983

File tree

7 files changed

+381
-79
lines changed

7 files changed

+381
-79
lines changed

Diff for: packages/ccip-js/README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# CCIP-JS
22

3-
43
CCIP-JS is a TypeScript library that provides a client for managing cross-chain token transfers that use Chainlink's [Cross-Chain Interoperability Protocol (CCIP)](https://docs.chain.link/ccip) routers. The library utilizes types and helper functions from [Viem](https://viem.sh/).
54

65
To learn more about CCIP, refer to the [CCIP documentation](https://docs.chain.link/ccip).
@@ -41,7 +40,6 @@ To learn more about CCIP, refer to the [CCIP documentation](https://docs.chain.l
4140
- [Contributing](#contributing)
4241
- [License](#license)
4342

44-
4543
## Why CCIP-JS?
4644

4745
CCIP-JS provides ready-to-use typesafe methods for every step of the token transfer process.
@@ -69,24 +67,25 @@ Additionally, after the transfer, you may need to check the transfer status.
6967
To install the package, use the following command:
7068

7169
```sh
72-
npm install @chainlink/ccip-js viem
70+
npm install @chainlink/ccip-js
7371
```
7472

7573
Or with Yarn:
7674

7775
```sh
78-
yarn add @chainlink/ccip-js viem
76+
yarn add @chainlink/ccip-js
7977
```
8078

8179
Or with PNPM:
8280

8381
```sh
84-
pnpm add @chainlink/ccip-js viem
82+
pnpm add @chainlink/ccip-js
8583
```
8684

8785
## Usage
8886

8987
This example code covers the following steps:
88+
9089
- Initialize CCIP-JS Client for mainnet
9190
- Approve tokens for transfer
9291
- Get fee for the transfer
@@ -593,11 +592,13 @@ pnpm build-ccip-js
593592

594593
#### Running tests
595594

596-
```sh
597-
pnpm i -w
598-
anvil
599-
pnpm test
600-
```
595+
1. cd into `packages/ccip-js` and then run `pnpm install` OR from the project root you can run `pnpm i -w`
596+
597+
2. open a new terminal window and run `anvil` - requires that you've [installed Foundry Anvil](https://book.getfoundry.sh/anvil/).
598+
599+
3. Back in the first terminal, inside, `packages/ccip-js` run `pnpm test`
600+
601+
<b?>Note:</b> that Anvil is only needed for the tests inside `./test/integration-mocked.test.ts` which uses the [Chainlink Local](https://github.com/smartcontractkit/chainlink-local) simulator. Actual testnet and mainnet behavior may differ from time to time and passing these tests does not guarantee testnet or mainnet behavior.
601602

602603
### Contributing
603604

Diff for: packages/ccip-js/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chainlink/ccip-js",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"private": false,
55
"main": "dist/api.js",
66
"types": "dist/api.d.ts",
@@ -15,7 +15,7 @@
1515
"lint": "eslint 'src/**/*.{ts,js}'",
1616
"format": "prettier --write 'src/**/*.{ts,js,json,md}'",
1717
"pretest": "anvil --block-time 2",
18-
"t:int": "jest --coverage -u -t=\"Integration\"",
18+
"t:int": "jest --coverage -u --testMatch=\"**/integration-*.test.ts\" --detectOpenHandles",
1919
"t:unit": "jest --coverage -u -t=\"Unit\"",
2020
"test": "jest --coverage",
2121
"test:hh": "hardhat test"

Diff for: packages/ccip-js/src/api.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ export interface Client {
281281
* @param {Viem.Address} options.routerAddress - The address of the router contract on the source blockchain.
282282
* @param {string} options.destinationChainSelector - The selector for the destination chain.
283283
* @param {Viem.Address} options.tokenAddress - The address of the token contract on the source blockchain.
284-
* @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the token
285-
* is supported on the destination chain.
284+
* @returns {Promise<boolean>} A promise that resolves to the Token Admin Registry Contract address on the source chain.
286285
* @example
287286
* import { createPublicClient, http } from 'viem'
288287
* import { mainnet } from 'viem/chains'
@@ -617,7 +616,7 @@ export const createClient = (): Client => {
617616

618617
const approveTxHash = await writeContract(options.client, {
619618
chain: options.client.chain,
620-
account: options.client.account!.address,
619+
account: options.client.account!,
621620
abi: IERC20ABI,
622621
address: options.tokenAddress,
623622
functionName: 'approve',
@@ -852,7 +851,7 @@ export const createClient = (): Client => {
852851
address: options.routerAddress,
853852
functionName: 'ccipSend',
854853
args: buildArgs(options),
855-
account: options.client.account!.address,
854+
account: options.client.account!,
856855
...(!options.feeTokenAddress && {
857856
value: await getFee(options),
858857
}),
@@ -905,7 +904,7 @@ export const createClient = (): Client => {
905904
address: options.routerAddress,
906905
functionName: 'ccipSend',
907906
args: buildArgs(options),
908-
account: options.client.account!.address,
907+
account: options.client.account!,
909908
...(!options.feeTokenAddress && {
910909
value: await getFee(options),
911910
}),

Diff for: packages/ccip-js/test/helpers/clients.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { account } from './constants'
22
import { createTestClient, http, publicActions, walletActions } from 'viem'
3-
import { hardhat, sepolia } from 'viem/chains'
3+
import { sepolia, anvil } from 'viem/chains'
44

55
export const testClient = createTestClient({
6-
chain: hardhat,
6+
chain: anvil,
77
transport: http(),
88
mode: 'anvil',
99
account,

Diff for: packages/ccip-js/test/helpers/constants.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@ import routerJson from '../../artifacts-compile/Router.json'
77
import simulatorJson from '../../artifacts-compile/CCIPLocalSimulator.json'
88
import priceRegistryJson from '../../artifacts-compile/PriceRegistry.json'
99

10-
// load.env file for private key
10+
// load.env file for private key
1111
// replace with your own private key (optional)
1212
dotenv.config()
1313

14-
// default anvil PK
15-
export const privateKey =
16-
(process.env.PRIVATE_KEY as Hex) || '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
17-
export const account = privateKeyToAccount(privateKey)
14+
if (process.env.PRIVATE_KEY?.slice(0, 2) !== '0x') {
15+
process.env.PRIVATE_KEY = `0x${process.env.PRIVATE_KEY}`
16+
}
17+
18+
export const DEFAULT_ANVIL_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
19+
export const account = privateKeyToAccount(DEFAULT_ANVIL_PRIVATE_KEY)
1820

1921
// bridge token contract
2022
export const { bridgeTokenAbi, bridgeTokenBin } = bridgeJson['contracts']['src/contracts/BridgeToken.sol:BridgeToken']
2123
// note: no need to deploy
2224
export const { onRampAbi, onRampBin } = onRampJson['contracts']['src/contracts/EVM2EVMOnRamp.sol:EVM2EVMOnRamp']
2325
export const { routerAbi, routerBin } = routerJson['contracts']['src/contracts/Router.sol:Router']
24-
export const { simulatorAbi, simulatorBin } = simulatorJson['contracts']['src/contracts/CCIPLocalSimulator.sol:CCIPLocalSimulator']
25-
export const { priceRegistryAbi, priceRegistryBin } = priceRegistryJson['contracts']['src/contracts/PriceRegistry.sol:PriceRegistry']
26+
export const { simulatorAbi, simulatorBin } =
27+
simulatorJson['contracts']['src/contracts/CCIPLocalSimulator.sol:CCIPLocalSimulator']
28+
export const { priceRegistryAbi, priceRegistryBin } =
29+
priceRegistryJson['contracts']['src/contracts/PriceRegistry.sol:PriceRegistry']
2630

2731
// CCIP testing data for simulations
2832
export const ccipTxHash = '0xc55d92b1212dd24db843e1cbbcaebb1fffe3cd1751313e0fd02cf26bf72b359e'
@@ -119,4 +123,4 @@ export const ccipTxReceipt: TransactionReceipt = {
119123
transactionHash: ccipTxHash,
120124
transactionIndex: 0,
121125
type: 'eip1559',
122-
}
126+
}

0 commit comments

Comments
 (0)