Skip to content

Commit

Permalink
core, node: Accept external key config in executeDeposit action
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Jan 15, 2025
1 parent 2abc6a6 commit 4660dcc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 35 deletions.
15 changes: 13 additions & 2 deletions packages/core/src/createExternalKeyConfig.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -15,10 +15,15 @@ export type CreateExternalKeyConfigParameters = {
*
*/
signMessage: (message: string) => Promise<SignMessageReturnType>
// 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
}

Expand All @@ -40,6 +45,8 @@ export function createExternalKeyConfig(
walletId,
publicKey: initialPublicKey,
websocketUrl,
viemClient,
darkPoolAddress,
} = parameters
invariant(
parameters.utils,
Expand Down Expand Up @@ -73,6 +80,8 @@ export function createExternalKeyConfig(
getSymmetricKey: () => {
return symmetricKey
},
viemClient,
darkPoolAddress,
}
}

Expand All @@ -85,4 +94,6 @@ export type ExternalConfig = BaseConfig & {
getBaseUrl: (route?: string) => string
renegadeKeyType: 'external'
setPublicKey: (newPublicKey: `0x${string}`) => void
viemClient?: PublicClient
darkPoolAddress: Address
}
1 change: 1 addition & 0 deletions packages/core/src/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export {
type BaseConfig,
type Config,
type CreateConfigParameters,
type RenegadeConfig,
type State,
createConfig,
} from '../createConfig.js'
Expand Down
3 changes: 2 additions & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 17 additions & 5 deletions packages/node/src/actions/executeDeposit.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -17,15 +18,24 @@ export type ExecuteDepositParameters = {
permit2Address: Address
walletClient: WalletClient
viemConfig: ReturnType<typeof createConfig>
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') {
Expand All @@ -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
Expand Down Expand Up @@ -91,6 +102,7 @@ export async function executeDeposit(
permitNonce: nonce,
permitDeadline: deadline,
permit: signature,
newPublicKey,
})

if (awaitTask) {
Expand Down
51 changes: 24 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4660dcc

Please sign in to comment.