diff --git a/.changeset/chilly-zebras-play.md b/.changeset/chilly-zebras-play.md new file mode 100644 index 000000000..6f9e5883b --- /dev/null +++ b/.changeset/chilly-zebras-play.md @@ -0,0 +1,5 @@ +--- +"@nocturne-xyz/frontend-sdk": major +--- + +Add withdrawFunds method to fe-sdk, add PrepareOperationOpts diff --git a/packages/config/configs/goerli.json b/packages/config/configs/goerli.json index 21b865a63..24cf67788 100644 --- a/packages/config/configs/goerli.json +++ b/packages/config/configs/goerli.json @@ -38,7 +38,7 @@ "screeners": ["0x44cD09776A1c3b803A5Fe30660528a61d36653B4"] }, "offchain": { - "finalityBlocks": 4, + "finalityBlocks": 1, "screeners": ["0x44cD09776A1c3b803A5Fe30660528a61d36653B4"], "subtreeBatchFillers": ["0x6556186E3E940930c40068C76BC875De95811E42"] }, diff --git a/packages/frontend-sdk/src/sdk.ts b/packages/frontend-sdk/src/sdk.ts index c73f9d290..bd9a9ea2c 100644 --- a/packages/frontend-sdk/src/sdk.ts +++ b/packages/frontend-sdk/src/sdk.ts @@ -24,6 +24,7 @@ import { DepositManager__factory, Handler, Handler__factory, + Teller__factory, } from "@nocturne-xyz/contracts"; import { DepositInstantiatedEvent } from "@nocturne-xyz/contracts/dist/src/DepositManager"; import { @@ -94,6 +95,7 @@ import { NocturneSdkConfig, OnChainDepositRequestStatus, OperationHandle, + PrepareOperationOpts, SelectedBatchPreference, SupportedNetwork, SupportedProvider, @@ -459,15 +461,14 @@ export class NocturneSdk { async prepareOperation( { request, meta }: OperationRequestWithMetadata, - batchPreference: SelectedBatchPreference, + { batchPreference, eoaProvidesGas }: PrepareOperationOpts, ): Promise> { const client = await this.clientThunk(); - const userSelectedMultiplier = - this.batchPreferenceGasMultipliers[batchPreference]; - const op = await client.prepareOperation( - request, - this.opGasMultiplier * userSelectedMultiplier, - ); + const gasMultiplier = eoaProvidesGas + ? 0 + : this.opGasMultiplier * + this.batchPreferenceGasMultipliers[batchPreference]; + const op = await client.prepareOperation(request, gasMultiplier); return { op, metadata: meta, @@ -499,6 +500,24 @@ export class NocturneSdk { return { op: _op, metadata }; } + // added 12/22/23 in support of Nocturne sunset + async withdrawFunds({ + op, + metadata, + }: OpWithMetadata): Promise { + const signed = await this.signOperation({ op, metadata }); + const submittable = await this.proveOperation(signed); + const teller = Teller__factory.connect( + this.sdkConfig.config.tellerAddress, + await this.signerThunk(), + ); + const tx = await teller.processBundle({ + operations: [submittable.op], + }); + + return tx; + } + async performOperation({ op, metadata, @@ -545,26 +564,26 @@ export class NocturneSdk { erc20Address: Address, amount: bigint, recipientAddress: Address, - batchPreference: SelectedBatchPreference, + opts: PrepareOperationOpts, ): Promise> { const operationRequest = await this.opRequestBuilder .use(Erc20Plugin) .erc20Transfer(erc20Address, recipientAddress, amount) .build(); - return await this.prepareOperation(operationRequest, batchPreference); + return await this.prepareOperation(operationRequest, opts); } async prepareAnonEthTransfer( recipientAddress: Address, amount: bigint, - batchPreference: SelectedBatchPreference, + opts: PrepareOperationOpts, ): Promise> { const operationRequest = await this.opRequestBuilder .use(EthTransferAdapterPlugin) .transferEth(recipientAddress, amount) .build(); - return await this.prepareOperation(operationRequest, batchPreference); + return await this.prepareOperation(operationRequest, opts); } async prepareAnonErc20Swap({ @@ -586,7 +605,7 @@ export class NocturneSdk { .swap(tokenIn, amountIn, tokenOut, { maxSlippageBps }) .build(); - return await this.prepareOperation(operationRequest, batchPreference); + return await this.prepareOperation(operationRequest, { batchPreference }); } async retrievePendingDeposit( diff --git a/packages/frontend-sdk/src/types.ts b/packages/frontend-sdk/src/types.ts index 6e8ea8116..7f274ca21 100644 --- a/packages/frontend-sdk/src/types.ts +++ b/packages/frontend-sdk/src/types.ts @@ -161,6 +161,15 @@ export interface GetBalanceOpts { } export type SelectedBatchPreference = "FAST" | "MEDIUM" | "SLOW"; +export type PrepareOperationOpts = + | { + batchPreference: SelectedBatchPreference; + eoaProvidesGas?: false; + } + | { + batchPreference?: undefined; + eoaProvidesGas: true; + }; export interface AnonSwapRequestParams { tokenIn: string;