diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 01b1948..c7dcbfc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,13 +32,16 @@ jobs: echo "::set-output name=version_changed::false"; fi - name: Use Node.js ${{ matrix.node-version }} - if: steps.check_version.outputs.version_changed == 'true' uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} registry-url: "https://registry.npmjs.org" - - run: npm install - - run: npm run build - - run: npm publish --provenance --access public + + - name: Publish to npm + if: steps.check_version.outputs.version_changed == 'true' + run: | + npm ci + npm run build + npm publish --provenance --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package-lock.json b/package-lock.json index ee04496..8a25670 100644 --- a/package-lock.json +++ b/package-lock.json @@ -971,6 +971,12 @@ "resolved": "src/eip4337", "link": true }, + "node_modules/@qng/meerchange-contracts": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@qng/meerchange-contracts/-/meerchange-contracts-0.0.1.tgz", + "integrity": "sha512-yZS9HDCErQyqcFO1i/2vQ37mIwF/xI4W9MPTbJ1RNFITpIsfrcIfAwv+5zgUx7FjfRk4gJ4yp9b/2JGrMyBAOQ==", + "dev": true + }, "node_modules/@tsconfig/node10": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", @@ -3066,11 +3072,13 @@ } }, "src/eip4337": { + "name": "@qng/eip4337-sdk", "version": "0.6.0", "license": "MIT", "devDependencies": { "@account-abstraction/sdk": "^0.6.0", - "@qng/eip4337-contracts": "^0.6.0" + "@qng/eip4337-contracts": "^0.6.0", + "@qng/meerchange-contracts": "^0.0.1" } } } diff --git a/src/eip4337/index.ts b/src/eip4337/index.ts index da79255..2edfef5 100644 --- a/src/eip4337/index.ts +++ b/src/eip4337/index.ts @@ -8,4 +8,11 @@ import { HttpRpcClient, BaseAccountAPI, } from "./qngAccountAPI"; -export { QngAccountAPI, PaymasterAPI, HttpRpcClient, BaseAccountAPI }; +import { MeerChangeAPI } from "./meerchange"; +export { + QngAccountAPI, + PaymasterAPI, + HttpRpcClient, + BaseAccountAPI, + MeerChangeAPI, +}; diff --git a/src/eip4337/meerchange.ts b/src/eip4337/meerchange.ts new file mode 100644 index 0000000..00840bc --- /dev/null +++ b/src/eip4337/meerchange.ts @@ -0,0 +1,47 @@ +import * as contracts from "@qng/meerchange-contracts"; + +import { Provider } from "@ethersproject/providers"; +import { ethers } from "ethers"; +export class MeerChangeAPI { + meerchangeContract: any; + meerchangeAddr: string; + provider: Provider; + constructor(params: any) { + this.provider = params.provider; + this.meerchangeAddr = params.meerchangeAddr; + } + async _getMeerChangeContract() { + if (this.meerchangeContract == null) { + this.meerchangeContract = await contracts.MeerChange__factory.connect( + await this.getMeerChangeAddress(), + this.provider + ); + } + return this.meerchangeContract; + } + async encodeExport4337( + txid: string, + idx: number, + fee: number, + signature: string + ) { + if (!txid.startsWith("0x")) { + txid = `0x${txid}`; + } + const meerchangeContract = await this._getMeerChangeContract(); + return meerchangeContract.interface.encodeFunctionData("export4337", [ + ethers.utils.hexZeroPad(txid, 32), + idx, + fee, + signature, + ]); + } + + async getMeerChangeAddress() { + // TODO + // { + // "id":1,"jsonrpc":"2.0","method":"qng_getMeerChangeAddress","params":[] + //} + return this.meerchangeAddr; + } +} diff --git a/src/eip4337/package.json b/src/eip4337/package.json index d4732ff..a8a8268 100644 --- a/src/eip4337/package.json +++ b/src/eip4337/package.json @@ -14,6 +14,7 @@ }, "keywords": [ "sdk", + "qitmeer", "qng", "smart", "contracts", @@ -26,6 +27,7 @@ }, "devDependencies": { "@qng/eip4337-contracts": "^0.6.0", + "@qng/meerchange-contracts": "^0.0.1", "@account-abstraction/sdk": "^0.6.0" } }