Skip to content
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
22 changes: 15 additions & 7 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,30 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
node-version: "22"

- name: Cache node modules
- name: Cache Bun dependencies
uses: actions/cache@v4
with:
path: |
~/.bun/install/cache
node_modules
~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
packages/*/node_modules
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-bun-

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install Dependencies
run: bun install --frozen-lockfile

- name: E2E Test
run: |
yarn --frozen-lockfile
yarn test e2e
bun test e2e
env:
MPC_CONTRACT_ID: v1.signer-prod.testnet
NEAR_ACCOUNT_ID: ${{secrets.NEAR_ACCOUNT_ID}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
registry-url: https://registry.npmjs.org/
- name: Build & Set Package Version to Tag
run: |
yarn --frozen-lockfile
yarn build
bun install --frozen-lockfile
bun run build
VERSION=${GITHUB_REF#refs/tags/}
npm version $VERSION --no-git-tag-version
- name: Publish
Expand Down
29 changes: 16 additions & 13 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Cache node modules
- name: Cache Bun dependencies
uses: actions/cache@v4
with:
path: |
~/.bun/install/cache
node_modules
~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
packages/*/node_modules
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-bun-

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install Dependencies
run: bun install --frozen-lockfile

- name: Install & Build
run: |
yarn --frozen-lockfile
yarn lint
yarn build
yarn verify
bun lint
bun run build
bun verify
12 changes: 6 additions & 6 deletions .github/workflows/upgrade.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Auto Yarn Upgrade
name: Auto Bun Update

on:
schedule:
Expand All @@ -21,12 +21,12 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
node-version: "22"

- name: Install and upgrade dependencies
run: |
yarn
yarn upgrade
bun i
bun update

- name: Commit changes
run: |
Expand All @@ -41,5 +41,5 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: upgrade dependencies
branch: auto-upgrade-branch
title: "Yarn Upgrade"
body: "This PR updates dependencies via `yarn upgrade`"
title: "Bun Update"
body: "This PR updates dependencies via `bun update`"
1,423 changes: 1,423 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"dist/**/*"
],
"scripts": {
"build": "rm -fr dist/* && yarn build:esm && yarn build:cjs",
"build": "rm -fr dist/* && bun build:esm && bun build:cjs",
"build:esm": "tsc -p tsconfig.esm.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"lint": "eslint . --ignore-pattern dist/ && prettier --check **/*.ts",
"test": "jest --passWithNoTests",
"coverage": "yarn test --coverage",
"verify": "yarn coverage unit",
"coverage": "bun test --coverage",
"verify": "bun coverage unit",
"fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}' && eslint src/ --fix"
},
"engines": {
Expand All @@ -39,19 +39,18 @@
"@reown/walletkit": "^1.2.4",
"elliptic": "^6.6.1",
"js-sha3": "^0.9.3",
"near-api-js": "^5.1.1",
"near-api-js": "^6.2.4",
"viem": "^2.29.3"
},
"devDependencies": {
"@types/elliptic": "^6.4.18",
"@types/jest": "^29.5.12",
"@types/node": "^22.13.5",
"@types/jest": "^30.0.0",
"@types/node": "^24.2.0",
"@typescript-eslint/eslint-plugin": "^8.21.0",
"@typescript-eslint/parser": "^8.21.0",
"dotenv": "^16.4.5",
"dotenv": "^17.2.1",
"eslint": "^9.19.0",
"ethers": "^6.13.3",
"jest": "^29.7.0",
"opensea-js": "^7.1.12",
"prettier": "^3.5.3",
"ts-jest": "^29.2.3",
Expand Down
15 changes: 8 additions & 7 deletions src/chains/near.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { keyStores, KeyPair, connect, Account } from "near-api-js";
import { KeyPair, Account, KeyPairSigner } from "near-api-js";
import { JsonRpcProvider, Provider } from "near-api-js/lib/providers";
import { NearConfig } from "near-api-js/lib/near";
import { NearAccountConfig } from "../types";

Expand Down Expand Up @@ -74,10 +75,10 @@ export const createNearAccount = async (
network: NearConfig,
keyPair?: KeyPair
): Promise<Account> => {
const keyStore = new keyStores.InMemoryKeyStore();
if (keyPair) {
await keyStore.setKey(network.networkId, accountId, keyPair);
}
const near = await connect({ ...network, keyStore });
return near.account(accountId);
const provider = new JsonRpcProvider({ url: network.nodeUrl }) as Provider;
return new Account(
accountId,
provider,
keyPair ? KeyPairSigner.fromSecretKey(keyPair.toString()) : undefined
);
};
27 changes: 4 additions & 23 deletions src/mpcContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class MpcContract implements IMpcContract {
this.connectedAccount = account;
this.rootPublicKey = rootPublicKey;

this.contract = new Contract(account.connection, contractId, {
this.contract = new Contract(account.getConnection(), contractId, {
changeMethods: ["sign"],
viewMethods: ["public_key", "experimental_signature_deposit"],
useLocalViewExecution: false,
Expand Down Expand Up @@ -164,35 +164,16 @@ export class MpcContract implements IMpcContract {
* @returns The execution outcome
*/
async signAndSendSignRequest(
transaction: FunctionCallTransaction<{ request: SignArgs }>,
blockTimeout: number = 30
transaction: FunctionCallTransaction<{ request: SignArgs }>
): Promise<FinalExecutionOutcome> {
const account = this.connectedAccount;
// @ts-expect-error: Account.signTransaction is protected (for no apparently good reason)
const [txHash, signedTx] = await account.signTransaction(
const signedTx = await account.createSignedTransaction(
this.contract.contractId,
transaction.actions.map(({ params: { args, gas, deposit } }) =>
transactions.functionCall("sign", args, BigInt(gas), BigInt(deposit))
)
);
const provider = account.connection.provider;
let outcome = await provider.sendTransactionAsync(signedTx);

let pings = 0;
while (
outcome.final_execution_status != "EXECUTED" &&
pings < blockTimeout
) {
await new Promise((resolve) => setTimeout(resolve, 1000));
outcome = await provider.txStatus(txHash, account.accountId, "INCLUDED");
pings += 1;
}
if (pings >= blockTimeout) {
console.warn(
`Request status polling exited before desired outcome.\n Current status: ${outcome.final_execution_status}\nSignature Request will likely fail.`
);
}
return outcome;
return account.provider.sendTransactionUntil(signedTx, "EXECUTED");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("End To End", () => {
});

it("Adapter.getBalance", async () => {
await expect(realAdapter.getBalance(chainId)).resolves.not.toThrow();
await expect(realAdapter.getBalance(chainId)).resolves.toBeDefined();
});

it.skip("signAndSendTransaction", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("ethereum", () => {
const request = await adapter.mpcSignRequest(transaction);
expect(request.actions.length).toEqual(1);

expect(() =>
await expect(
adapter.beta.handleSessionRequest({
params: {
chainId: "11155111",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("index", () => {
network: configFromNetworkId(networkId),
mpcContractId,
};
await expect(() => setupAdapter(config)).rejects.toThrow(
await expect(setupAdapter(config)).rejects.toThrow(
`accountId ${accountId} doesn't match the networkId ${networkId}. Please ensure that your accountId is correct and corresponds to the intended network.`
);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/types.util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("types/utils", () => {

it("convertToCompatibleFormat fails", async () => {
expect(() => convertToCompatibleFormat(1n)).toThrow(
"Failed to convert the input: Do not know how to serialize a BigInt"
"Failed to convert the input: JSON.stringify cannot serialize BigInt."
);
});
});
2 changes: 1 addition & 1 deletion tests/unit/utils/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("Transaction Builder Functions", () => {
chainId: 11155111,
to: zeroAddress,
};
await expect(() =>
await expect(
populateTx(baseTx, zeroAddress, Network.fromChainId(100).client)
).rejects.toThrow("client chainId=100 mismatch with tx.chainId=11155111");

Expand Down
Loading