Skip to content

Commit 2880d86

Browse files
authored
NearApiJS v6 (#179)
Migrates project to bun (from yarn) and upgrades near-api dependency
1 parent 813d80f commit 2880d86

14 files changed

Lines changed: 1486 additions & 4213 deletions

File tree

.github/workflows/e2e.yaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,30 @@ jobs:
1313
- name: Set up Node.js
1414
uses: actions/setup-node@v4
1515
with:
16-
node-version: "20"
16+
node-version: "22"
1717

18-
- name: Cache node modules
18+
- name: Cache Bun dependencies
1919
uses: actions/cache@v4
2020
with:
2121
path: |
22+
~/.bun/install/cache
2223
node_modules
23-
~/.cache/yarn
24-
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
24+
packages/*/node_modules
25+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
2526
restore-keys: |
26-
${{ runner.os }}-yarn-
27+
${{ runner.os }}-bun-
28+
29+
- name: Setup Bun
30+
uses: oven-sh/setup-bun@v2
31+
with:
32+
bun-version: latest
33+
34+
- name: Install Dependencies
35+
run: bun install --frozen-lockfile
2736

2837
- name: E2E Test
2938
run: |
30-
yarn --frozen-lockfile
31-
yarn test e2e
39+
bun test e2e
3240
env:
3341
MPC_CONTRACT_ID: v1.signer-prod.testnet
3442
NEAR_ACCOUNT_ID: ${{secrets.NEAR_ACCOUNT_ID}}

.github/workflows/publish.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
registry-url: https://registry.npmjs.org/
1616
- name: Build & Set Package Version to Tag
1717
run: |
18-
yarn --frozen-lockfile
19-
yarn build
18+
bun install --frozen-lockfile
19+
bun run build
2020
VERSION=${GITHUB_REF#refs/tags/}
2121
npm version $VERSION --no-git-tag-version
2222
- name: Publish

.github/workflows/pull-request.yaml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,27 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414

15-
- name: Set up Node.js
16-
uses: actions/setup-node@v4
17-
with:
18-
node-version: "20"
19-
20-
- name: Cache node modules
15+
- name: Cache Bun dependencies
2116
uses: actions/cache@v4
2217
with:
2318
path: |
19+
~/.bun/install/cache
2420
node_modules
25-
~/.cache/yarn
26-
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
21+
packages/*/node_modules
22+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
2723
restore-keys: |
28-
${{ runner.os }}-yarn-
24+
${{ runner.os }}-bun-
25+
26+
- name: Setup Bun
27+
uses: oven-sh/setup-bun@v2
28+
with:
29+
bun-version: latest
30+
31+
- name: Install Dependencies
32+
run: bun install --frozen-lockfile
2933

3034
- name: Install & Build
3135
run: |
32-
yarn --frozen-lockfile
33-
yarn lint
34-
yarn build
35-
yarn verify
36+
bun lint
37+
bun run build
38+
bun verify

.github/workflows/upgrade.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Auto Yarn Upgrade
1+
name: Auto Bun Update
22

33
on:
44
schedule:
@@ -21,12 +21,12 @@ jobs:
2121
- name: Set up Node.js
2222
uses: actions/setup-node@v4
2323
with:
24-
node-version: "20"
24+
node-version: "22"
2525

2626
- name: Install and upgrade dependencies
2727
run: |
28-
yarn
29-
yarn upgrade
28+
bun i
29+
bun update
3030
3131
- name: Commit changes
3232
run: |
@@ -41,5 +41,5 @@ jobs:
4141
token: ${{ secrets.GITHUB_TOKEN }}
4242
commit-message: upgrade dependencies
4343
branch: auto-upgrade-branch
44-
title: "Yarn Upgrade"
45-
body: "This PR updates dependencies via `yarn upgrade`"
44+
title: "Bun Update"
45+
body: "This PR updates dependencies via `bun update`"

bun.lock

Lines changed: 1423 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
"dist/**/*"
2424
],
2525
"scripts": {
26-
"build": "rm -fr dist/* && yarn build:esm && yarn build:cjs",
26+
"build": "rm -fr dist/* && bun build:esm && bun build:cjs",
2727
"build:esm": "tsc -p tsconfig.esm.json",
2828
"build:cjs": "tsc -p tsconfig.cjs.json",
2929
"lint": "eslint . --ignore-pattern dist/ && prettier --check **/*.ts",
3030
"test": "jest --passWithNoTests",
31-
"coverage": "yarn test --coverage",
32-
"verify": "yarn coverage unit",
31+
"coverage": "bun test --coverage",
32+
"verify": "bun coverage unit",
3333
"fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}' && eslint src/ --fix"
3434
},
3535
"engines": {
@@ -39,19 +39,18 @@
3939
"@reown/walletkit": "^1.2.4",
4040
"elliptic": "^6.6.1",
4141
"js-sha3": "^0.9.3",
42-
"near-api-js": "^5.1.1",
42+
"near-api-js": "^6.2.4",
4343
"viem": "^2.29.3"
4444
},
4545
"devDependencies": {
4646
"@types/elliptic": "^6.4.18",
47-
"@types/jest": "^29.5.12",
48-
"@types/node": "^22.13.5",
47+
"@types/jest": "^30.0.0",
48+
"@types/node": "^24.2.0",
4949
"@typescript-eslint/eslint-plugin": "^8.21.0",
5050
"@typescript-eslint/parser": "^8.21.0",
51-
"dotenv": "^16.4.5",
51+
"dotenv": "^17.2.1",
5252
"eslint": "^9.19.0",
5353
"ethers": "^6.13.3",
54-
"jest": "^29.7.0",
5554
"opensea-js": "^7.1.12",
5655
"prettier": "^3.5.3",
5756
"ts-jest": "^29.2.3",

src/chains/near.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { keyStores, KeyPair, connect, Account } from "near-api-js";
1+
import { KeyPair, Account, KeyPairSigner } from "near-api-js";
2+
import { JsonRpcProvider, Provider } from "near-api-js/lib/providers";
23
import { NearConfig } from "near-api-js/lib/near";
34
import { NearAccountConfig } from "../types";
45

@@ -74,10 +75,10 @@ export const createNearAccount = async (
7475
network: NearConfig,
7576
keyPair?: KeyPair
7677
): Promise<Account> => {
77-
const keyStore = new keyStores.InMemoryKeyStore();
78-
if (keyPair) {
79-
await keyStore.setKey(network.networkId, accountId, keyPair);
80-
}
81-
const near = await connect({ ...network, keyStore });
82-
return near.account(accountId);
78+
const provider = new JsonRpcProvider({ url: network.nodeUrl }) as Provider;
79+
return new Account(
80+
accountId,
81+
provider,
82+
keyPair ? KeyPairSigner.fromSecretKey(keyPair.toString()) : undefined
83+
);
8384
};

src/mpcContract.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class MpcContract implements IMpcContract {
5858
this.connectedAccount = account;
5959
this.rootPublicKey = rootPublicKey;
6060

61-
this.contract = new Contract(account.connection, contractId, {
61+
this.contract = new Contract(account.getConnection(), contractId, {
6262
changeMethods: ["sign"],
6363
viewMethods: ["public_key", "experimental_signature_deposit"],
6464
useLocalViewExecution: false,
@@ -164,35 +164,16 @@ export class MpcContract implements IMpcContract {
164164
* @returns The execution outcome
165165
*/
166166
async signAndSendSignRequest(
167-
transaction: FunctionCallTransaction<{ request: SignArgs }>,
168-
blockTimeout: number = 30
167+
transaction: FunctionCallTransaction<{ request: SignArgs }>
169168
): Promise<FinalExecutionOutcome> {
170169
const account = this.connectedAccount;
171-
// @ts-expect-error: Account.signTransaction is protected (for no apparently good reason)
172-
const [txHash, signedTx] = await account.signTransaction(
170+
const signedTx = await account.createSignedTransaction(
173171
this.contract.contractId,
174172
transaction.actions.map(({ params: { args, gas, deposit } }) =>
175173
transactions.functionCall("sign", args, BigInt(gas), BigInt(deposit))
176174
)
177175
);
178-
const provider = account.connection.provider;
179-
let outcome = await provider.sendTransactionAsync(signedTx);
180-
181-
let pings = 0;
182-
while (
183-
outcome.final_execution_status != "EXECUTED" &&
184-
pings < blockTimeout
185-
) {
186-
await new Promise((resolve) => setTimeout(resolve, 1000));
187-
outcome = await provider.txStatus(txHash, account.accountId, "INCLUDED");
188-
pings += 1;
189-
}
190-
if (pings >= blockTimeout) {
191-
console.warn(
192-
`Request status polling exited before desired outcome.\n Current status: ${outcome.final_execution_status}\nSignature Request will likely fail.`
193-
);
194-
}
195-
return outcome;
176+
return account.provider.sendTransactionUntil(signedTx, "EXECUTED");
196177
}
197178
}
198179

tests/e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("End To End", () => {
2626
});
2727

2828
it("Adapter.getBalance", async () => {
29-
await expect(realAdapter.getBalance(chainId)).resolves.not.toThrow();
29+
await expect(realAdapter.getBalance(chainId)).resolves.toBeDefined();
3030
});
3131

3232
it.skip("signAndSendTransaction", async () => {

tests/unit/ethereum.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("ethereum", () => {
3030
const request = await adapter.mpcSignRequest(transaction);
3131
expect(request.actions.length).toEqual(1);
3232

33-
expect(() =>
33+
await expect(
3434
adapter.beta.handleSessionRequest({
3535
params: {
3636
chainId: "11155111",

0 commit comments

Comments
 (0)