From 4660dcc9fb0cb80ef06db166ece5e5f105289b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sehyun=20Chung=20=E2=9C=8C=EF=B8=8E?= <41171808+sehyunc@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:52:30 -0800 Subject: [PATCH] core, node: Accept external key config in executeDeposit action --- packages/core/src/createExternalKeyConfig.ts | 15 +++++- packages/core/src/exports/index.ts | 1 + packages/node/package.json | 3 +- packages/node/src/actions/executeDeposit.ts | 22 +++++++-- pnpm-lock.yaml | 51 +++++++++----------- 5 files changed, 57 insertions(+), 35 deletions(-) diff --git a/packages/core/src/createExternalKeyConfig.ts b/packages/core/src/createExternalKeyConfig.ts index 8e28ab48..6a4e7a3d 100644 --- a/packages/core/src/createExternalKeyConfig.ts +++ b/packages/core/src/createExternalKeyConfig.ts @@ -1,5 +1,5 @@ import invariant from 'tiny-invariant' -import type { SignMessageReturnType } from 'viem' +import type { Address, PublicClient, SignMessageReturnType } from 'viem' import type { BaseConfig } from './createConfig.js' import type * as rustUtils from './utils.d.ts' @@ -15,10 +15,15 @@ export type CreateExternalKeyConfigParameters = { * */ signMessage: (message: string) => Promise - // Wallet secrets generated by offline script + /** Wallet secrets generated by offline script */ symmetricKey: `0x${string}` walletId: string publicKey: `0x${string}` + /** Viem client */ + viemClient?: PublicClient + /** Dark pool address */ + darkPoolAddress: Address + /** Utils */ utils?: typeof rustUtils } @@ -40,6 +45,8 @@ export function createExternalKeyConfig( walletId, publicKey: initialPublicKey, websocketUrl, + viemClient, + darkPoolAddress, } = parameters invariant( parameters.utils, @@ -73,6 +80,8 @@ export function createExternalKeyConfig( getSymmetricKey: () => { return symmetricKey }, + viemClient, + darkPoolAddress, } } @@ -85,4 +94,6 @@ export type ExternalConfig = BaseConfig & { getBaseUrl: (route?: string) => string renegadeKeyType: 'external' setPublicKey: (newPublicKey: `0x${string}`) => void + viemClient?: PublicClient + darkPoolAddress: Address } diff --git a/packages/core/src/exports/index.ts b/packages/core/src/exports/index.ts index 939efeb6..75783e3c 100644 --- a/packages/core/src/exports/index.ts +++ b/packages/core/src/exports/index.ts @@ -240,6 +240,7 @@ export { type BaseConfig, type Config, type CreateConfigParameters, + type RenegadeConfig, type State, createConfig, } from '../createConfig.js' diff --git a/packages/node/package.json b/packages/node/package.json index 85b3cd55..763aeb10 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -50,7 +50,8 @@ }, "dependencies": { "@renegade-fi/core": "workspace:*", - "@wagmi/core": "^2.13.4" + "@wagmi/core": "^2.13.4", + "tiny-invariant": "^1.3.3" }, "devDependencies": { "@wagmi/cli": "^2.1.15" diff --git a/packages/node/src/actions/executeDeposit.ts b/packages/node/src/actions/executeDeposit.ts index 5be16ec2..3959166f 100644 --- a/packages/node/src/actions/executeDeposit.ts +++ b/packages/node/src/actions/executeDeposit.ts @@ -1,12 +1,13 @@ import { - type Config, type DepositReturnType, + type RenegadeConfig, deposit, getBackOfQueueWallet, getPkRootScalars, waitForTaskCompletionWs, } from '@renegade-fi/core' import { type createConfig, waitForTransactionReceipt } from '@wagmi/core' +import invariant from 'tiny-invariant' import { type Address, type WalletClient, zeroAddress } from 'viem' import { readErc20Allowance, writeErc20Approve } from '../generated.js' import { signPermit2 } from '../utils/permit2.js' @@ -17,15 +18,24 @@ export type ExecuteDepositParameters = { permit2Address: Address walletClient: WalletClient viemConfig: ReturnType - awaitTask: boolean + awaitTask?: boolean + newPublicKey?: string } export async function executeDeposit( - config: Config, + config: RenegadeConfig, parameters: ExecuteDepositParameters, ): DepositReturnType { - const { mint, amount, permit2Address, walletClient, viemConfig, awaitTask } = - parameters + const { + mint, + amount, + permit2Address, + walletClient, + viemConfig, + awaitTask, + newPublicKey, + } = parameters + invariant(config.viemClient, 'Viem client is required') const chainId = config.viemClient.chain?.id if (mint === zeroAddress || mint === '0x') { @@ -51,6 +61,7 @@ export async function executeDeposit( address: mint, account: walletClient.account, args: [walletClient.account.address, permit2Address], + chainId, }) // If not enough allowance, approve max amount @@ -91,6 +102,7 @@ export async function executeDeposit( permitNonce: nonce, permitDeadline: deadline, permit: signature, + newPublicKey, }) if (awaitTask) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b4f54cc2..874886b0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,7 +68,10 @@ importers: version: link:../core '@wagmi/core': specifier: ^2.13.4 - version: 2.13.4(@tanstack/query-core@5.52.0)(@types/react@18.3.4)(react@18.3.1)(typescript@5.5.4)(viem@2.20.0(typescript@5.5.4)(zod@3.23.8)) + version: 2.16.3(@tanstack/query-core@5.52.0)(@types/react@18.3.4)(react@18.3.1)(typescript@5.5.4)(use-sync-external-store@1.2.2(react@18.3.1))(viem@2.20.0(typescript@5.5.4)(zod@3.23.8)) + tiny-invariant: + specifier: ^1.3.3 + version: 1.3.3 viem: specifier: 2.x version: 2.20.0(typescript@5.5.4)(zod@3.23.8) @@ -774,8 +777,8 @@ packages: typescript: optional: true - '@wagmi/core@2.13.4': - resolution: {integrity: sha512-J6gfxHYr8SCc/BzEa712LnI+qLFs5K2nBLupwQqQl4WiAlCu8SdcpbZokqiwfCMYhIRMj0+YFEP9qe4ypcexmw==} + '@wagmi/core@2.16.3': + resolution: {integrity: sha512-SVovoWHaQ2AIkmGf+ucNijT6AHXcTMffFcLmcFF6++y21x+ge7Gkh3UoJiU91SDDv8n08eTQ9jbyia3GEgU5jQ==} peerDependencies: '@tanstack/query-core': '>=5.0.0' typescript: '>=5.0.4' @@ -1659,11 +1662,6 @@ packages: resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==} engines: {node: '>= 10.0.0'} - use-sync-external-store@1.2.0: - resolution: {integrity: sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==} - peerDependencies: - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - use-sync-external-store@1.2.2: resolution: {integrity: sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==} peerDependencies: @@ -1817,12 +1815,12 @@ packages: zod@3.23.8: resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} - zustand@4.4.1: - resolution: {integrity: sha512-QCPfstAS4EBiTQzlaGP1gmorkh/UL1Leaj2tdj+zZCZ/9bm0WS7sI2wnfD5lpOszFqWJ1DcPnGoY8RDL61uokw==} + zustand@4.5.5: + resolution: {integrity: sha512-+0PALYNJNgK6hldkgDq2vLrw5f6g/jCInz52n9RTpropGgeAf/ioFUCdtsjCqu4gNhW9D01rUQBROoRjdzyn2Q==} engines: {node: '>=12.7.0'} peerDependencies: '@types/react': '>=16.8' - immer: '>=9.0' + immer: '>=9.0.6' react: '>=16.8' peerDependenciesMeta: '@types/react': @@ -1832,13 +1830,14 @@ packages: react: optional: true - zustand@4.5.5: - resolution: {integrity: sha512-+0PALYNJNgK6hldkgDq2vLrw5f6g/jCInz52n9RTpropGgeAf/ioFUCdtsjCqu4gNhW9D01rUQBROoRjdzyn2Q==} - engines: {node: '>=12.7.0'} + zustand@5.0.0: + resolution: {integrity: sha512-LE+VcmbartOPM+auOjCCLQOsQ05zUTp8RkgwRzefUk+2jISdMMFnxvyTjA4YNWr5ZGXYbVsEMZosttuxUBkojQ==} + engines: {node: '>=12.20.0'} peerDependencies: - '@types/react': '>=16.8' + '@types/react': '>=18.0.0' immer: '>=9.0.6' - react: '>=16.8' + react: '>=18.0.0' + use-sync-external-store: '>=1.2.0' peerDependenciesMeta: '@types/react': optional: true @@ -1846,6 +1845,8 @@ packages: optional: true react: optional: true + use-sync-external-store: + optional: true snapshots: @@ -2430,12 +2431,12 @@ snapshots: - bufferutil - utf-8-validate - '@wagmi/core@2.13.4(@tanstack/query-core@5.52.0)(@types/react@18.3.4)(react@18.3.1)(typescript@5.5.4)(viem@2.20.0(typescript@5.5.4)(zod@3.23.8))': + '@wagmi/core@2.16.3(@tanstack/query-core@5.52.0)(@types/react@18.3.4)(react@18.3.1)(typescript@5.5.4)(use-sync-external-store@1.2.2(react@18.3.1))(viem@2.20.0(typescript@5.5.4)(zod@3.23.8))': dependencies: eventemitter3: 5.0.1 mipd: 0.0.7(typescript@5.5.4) viem: 2.20.0(typescript@5.5.4)(zod@3.23.8) - zustand: 4.4.1(@types/react@18.3.4)(react@18.3.1) + zustand: 5.0.0(@types/react@18.3.4)(react@18.3.1)(use-sync-external-store@1.2.2(react@18.3.1)) optionalDependencies: '@tanstack/query-core': 5.52.0 typescript: 5.5.4 @@ -2443,6 +2444,7 @@ snapshots: - '@types/react' - immer - react + - use-sync-external-store abitype@1.0.5(typescript@5.5.4)(zod@3.23.8): optionalDependencies: @@ -3279,10 +3281,6 @@ snapshots: universalify@2.0.1: {} - use-sync-external-store@1.2.0(react@18.3.1): - dependencies: - react: 18.3.1 - use-sync-external-store@1.2.2(react@18.3.1): dependencies: react: 18.3.1 @@ -3430,16 +3428,15 @@ snapshots: zod@3.23.8: {} - zustand@4.4.1(@types/react@18.3.4)(react@18.3.1): + zustand@4.5.5(@types/react@18.3.4)(react@18.3.1): dependencies: - use-sync-external-store: 1.2.0(react@18.3.1) + use-sync-external-store: 1.2.2(react@18.3.1) optionalDependencies: '@types/react': 18.3.4 react: 18.3.1 - zustand@4.5.5(@types/react@18.3.4)(react@18.3.1): - dependencies: - use-sync-external-store: 1.2.2(react@18.3.1) + zustand@5.0.0(@types/react@18.3.4)(react@18.3.1)(use-sync-external-store@1.2.2(react@18.3.1)): optionalDependencies: '@types/react': 18.3.4 react: 18.3.1 + use-sync-external-store: 1.2.2(react@18.3.1)