diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0cced95 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: release +on: + push: + branches: + - develop + - main + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + + - uses: pnpm/action-setup@v2 + name: install-pnpm + id: pnpm-install + with: + version: 8 + run_install: false + + - uses: actions/setup-node@v3 + with: + node-version: 18 + + - run: pnpm install --frozen-lockfile + - run: pnpm run build + + - name: semantic-release + run: npx semantic-release --debug true --dry-run false + env: + GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.CI_NPM_TOKEN }} diff --git a/package.json b/package.json index 59d1d01..3405d2f 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@commitlint/cli": "^19.2.1", "@commitlint/config-conventional": "^19.1.0", "@rollup/plugin-node-resolve": "^15.0.0", + "@semantic-release/git": "^10.0.1", "@types/minimalistic-assert": "^1.0.1", "@typescript-eslint/eslint-plugin": "^7.5.0", "@vitest/browser": "1.3.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 57c21b0..e338327 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,6 +28,9 @@ devDependencies: '@rollup/plugin-node-resolve': specifier: ^15.0.0 version: 15.0.0 + '@semantic-release/git': + specifier: ^10.0.1 + version: 10.0.1(semantic-release@23.0.6) '@types/minimalistic-assert': specifier: ^1.0.1 version: 1.0.1 @@ -1198,11 +1201,35 @@ packages: - supports-color dev: true + /@semantic-release/error@3.0.0: + resolution: {integrity: sha512-5hiM4Un+tpl4cKw3lV4UgzJj+SmfNIDCLLw0TepzQxz9ZGV5ixnqkzIVF+3tp0ZHgcMKE+VNGHJjEeyFG2dcSw==} + engines: {node: '>=14.17'} + dev: true + /@semantic-release/error@4.0.0: resolution: {integrity: sha512-mgdxrHTLOjOddRVYIYDo0fR3/v61GNN1YGkfbrjuIKg/uMgCd+Qzo3UAXJ+woLQQpos4pl5Esuw5A7AoNlzjUQ==} engines: {node: '>=18'} dev: true + /@semantic-release/git@10.0.1(semantic-release@23.0.6): + resolution: {integrity: sha512-eWrx5KguUcU2wUPaO6sfvZI0wPafUKAMNC18aXY4EnNcrZL86dEmpNVnC9uMpGZkmZJ9EfCVJBQx4pV4EMGT1w==} + engines: {node: '>=14.17'} + peerDependencies: + semantic-release: '>=18.0.0' + dependencies: + '@semantic-release/error': 3.0.0 + aggregate-error: 3.1.0 + debug: 4.3.4(supports-color@8.1.1) + dir-glob: 3.0.1 + execa: 5.1.1 + lodash: 4.17.21 + micromatch: 4.0.5 + p-reduce: 2.1.0 + semantic-release: 23.0.6(typescript@5.4.3) + transitivePeerDependencies: + - supports-color + dev: true + /@semantic-release/github@10.0.2(semantic-release@23.0.6): resolution: {integrity: sha512-SP5ihhv/uQa8vPuWKmbJrrzfv8lRUkDFC6qwgaWoorrflN1DEW0IGCa9w/PxUp8Ad3dbvXZPmpXdGiP3eyTzhg==} engines: {node: '>=20.8.1'} @@ -1711,6 +1738,14 @@ packages: - supports-color dev: true + /aggregate-error@3.1.0: + resolution: {integrity: sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==} + engines: {node: '>=8'} + dependencies: + clean-stack: 2.2.0 + indent-string: 4.0.0 + dev: true + /aggregate-error@5.0.0: resolution: {integrity: sha512-gOsf2YwSlleG6IjRYG2A7k0HmBMEo6qVNk9Bp/EaLgAJT5ngH6PXbqa4ItvnEwCm/velL5jAnQgsHsWnjhGmvw==} engines: {node: '>=18'} @@ -2097,6 +2132,11 @@ packages: fsevents: 2.3.3 dev: false + /clean-stack@2.2.0: + resolution: {integrity: sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==} + engines: {node: '>=6'} + dev: true + /clean-stack@3.0.1: resolution: {integrity: sha512-lR9wNiMRcVQjSB3a7xXGLuz4cr4wJuuXlaAEbRutGowQTmlp7R72/DOgN21e8jdwblMWl9UOJMJXarX94pzKdg==} engines: {node: '>=10'} @@ -2929,6 +2969,21 @@ packages: resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==} dev: true + /execa@5.1.1: + resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} + engines: {node: '>=10'} + dependencies: + cross-spawn: 7.0.3 + get-stream: 6.0.1 + human-signals: 2.1.0 + is-stream: 2.0.1 + merge-stream: 2.0.0 + npm-run-path: 4.0.1 + onetime: 5.1.2 + signal-exit: 3.0.7 + strip-final-newline: 2.0.0 + dev: true + /execa@8.0.1: resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==} engines: {node: '>=16.17'} @@ -3453,6 +3508,11 @@ packages: - supports-color dev: true + /human-signals@2.1.0: + resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} + engines: {node: '>=10.17.0'} + dev: true + /human-signals@5.0.0: resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==} engines: {node: '>=16.17.0'} @@ -3526,7 +3586,6 @@ packages: /indent-string@4.0.0: resolution: {integrity: sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==} engines: {node: '>=8'} - dev: false /indent-string@5.0.0: resolution: {integrity: sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg==} @@ -3751,6 +3810,11 @@ packages: call-bind: 1.0.7 dev: true + /is-stream@2.0.1: + resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} + engines: {node: '>=8'} + dev: true + /is-stream@3.0.0: resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -4415,6 +4479,13 @@ packages: engines: {node: '>=14.16'} dev: true + /npm-run-path@4.0.1: + resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} + engines: {node: '>=8'} + dependencies: + path-key: 3.1.1 + dev: true + /npm-run-path@5.3.0: resolution: {integrity: sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -4687,6 +4758,11 @@ packages: engines: {node: '>=18'} dev: true + /p-reduce@2.1.0: + resolution: {integrity: sha512-2USApvnsutq8uoxZBGbbWM0JIYLiEMJ9RlaN7fAzVNb9OZN0SHjjTTfIcb667XynS5Y1VhwDJVDa72TnPzAYWw==} + engines: {node: '>=8'} + dev: true + /p-reduce@3.0.0: resolution: {integrity: sha512-xsrIUgI0Kn6iyDYm9StOpOeK29XM1aboGji26+QEortiFST1hGZaUQOLhtEbqHErPpGW/aSz6allwK2qcptp0Q==} engines: {node: '>=12'} @@ -5604,6 +5680,11 @@ packages: engines: {node: '>=4'} dev: true + /strip-final-newline@2.0.0: + resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} + engines: {node: '>=6'} + dev: true + /strip-final-newline@3.0.0: resolution: {integrity: sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==} engines: {node: '>=12'} diff --git a/src/interface.ts b/src/interface.ts new file mode 100644 index 0000000..62ae949 --- /dev/null +++ b/src/interface.ts @@ -0,0 +1,15 @@ +import { BigNumberish, Call, types } from "starknet" + +export type OffchainSessionDetails = { + nonce: BigNumberish + maxFee: BigNumberish | undefined + version: `${types.RPC.ETransactionVersion}` +} + +export type OffchainSessionCall = Call & { + offchainSessionDetails?: OffchainSessionDetails +} + +export interface OffchainSessionAddInvokeTransactionParameters { + calls: OffchainSessionCall[] +} diff --git a/src/offchainSessionAccount.ts b/src/offchainSessionAccount.ts index 11d4117..545a276 100644 --- a/src/offchainSessionAccount.ts +++ b/src/offchainSessionAccount.ts @@ -21,6 +21,7 @@ import { stark, } from "starknet" import { ensureArray } from "./ensureArray" +import { OffchainSessionCall, OffchainSessionDetails } from "./interface" const OFFCHAIN_SESSION_ENTRYPOINT = "use_offchain_session" @@ -39,7 +40,10 @@ export class OffchainSessionAccount super(providerOrOptions, address, pkOrSigner, "1") } - private async sessionToCall(dappSignature: Signature): Promise { + private async sessionToCall( + dappSignature: Signature, + offchainSessionDetails: OffchainSessionDetails, + ): Promise { const signature = stark.formatSignature(this.sessionSignature) const formattedDappSignature = stark.formatSignature(dappSignature) @@ -57,14 +61,19 @@ export class OffchainSessionAccount token5: signature[2], token6: signature[3], }), + offchainSessionDetails, } } private async extendCallsBySession( calls: Call[], dappSignature: Signature, - ): Promise { - const sessionCall = await this.sessionToCall(dappSignature) + offchainSessionDetails: OffchainSessionDetails, + ): Promise { + const sessionCall = await this.sessionToCall( + dappSignature, + offchainSessionDetails, + ) return [sessionCall, ...calls] } @@ -92,47 +101,45 @@ export class OffchainSessionAccount let maxFee = transactionsDetail.maxFee - if (!maxFee) { - try { - const sim = await this.simulateTransaction( - [ - { - type: TransactionType.INVOKE, - payload: calls, - }, - ], + try { + const sim = await this.simulateTransaction( + [ + { + type: TransactionType.INVOKE, + payload: calls, + }, + ], + { + skipValidate: true, + nonce, + }, + ) + + const [estimation] = sim + const { fee_estimation } = estimation + const overall_fee = fee_estimation.overall_fee + + maxFee = estimation.suggestedMaxFee ?? overall_fee + } catch (e) { + // fallback + maxFee = ( + await this.getSuggestedFee( + { + type: TransactionType.INVOKE, + payload: calls, + }, { skipValidate: true, nonce, }, ) - - const [estimation] = sim - const { fee_estimation } = estimation - const overall_fee = fee_estimation.overall_fee - - maxFee = estimation.suggestedMaxFee ?? overall_fee - } catch (e) { - // fallback - maxFee = ( - await this.getSuggestedFee( - { - type: TransactionType.INVOKE, - payload: calls, - }, - { - skipValidate: true, - nonce, - }, - ) - ).suggestedMaxFee - } + ).suggestedMaxFee } const signerDetails: InvocationsSignerDetails = { walletAddress: this.account.address, nonce, - maxFee, + maxFee: maxFee, version: "0x1" as const, chainId, cairoVersion: this.cairoVersion ?? "1", @@ -147,6 +154,7 @@ export class OffchainSessionAccount const transactionsWithSession = await this.extendCallsBySession( transactions, dappSignature, + { nonce, maxFee: maxFee.toString(), version: "0x1" as const }, ) const invokeParams: AddInvokeTransactionParameters = { @@ -154,6 +162,7 @@ export class OffchainSessionAccount contract_address: t.contractAddress, entrypoint: t.entrypoint, calldata: t.calldata as string[], + offchainSessionDetails: t.offchainSessionDetails, })), }