Skip to content

Commit

Permalink
Add withdraw funds sunset (#676)
Browse files Browse the repository at this point in the history
* add withdrawFunds method, tweak opts

* PR feedback
  • Loading branch information
panieldark authored Jan 3, 2024
1 parent b7e69a4 commit fa234de
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-zebras-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nocturne-xyz/frontend-sdk": major
---

Add withdrawFunds method to fe-sdk, add PrepareOperationOpts
2 changes: 1 addition & 1 deletion packages/config/configs/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"screeners": ["0x44cD09776A1c3b803A5Fe30660528a61d36653B4"]
},
"offchain": {
"finalityBlocks": 4,
"finalityBlocks": 1,
"screeners": ["0x44cD09776A1c3b803A5Fe30660528a61d36653B4"],
"subtreeBatchFillers": ["0x6556186E3E940930c40068C76BC875De95811E42"]
},
Expand Down
43 changes: 31 additions & 12 deletions packages/frontend-sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -94,6 +95,7 @@ import {
NocturneSdkConfig,
OnChainDepositRequestStatus,
OperationHandle,
PrepareOperationOpts,
SelectedBatchPreference,
SupportedNetwork,
SupportedProvider,
Expand Down Expand Up @@ -459,15 +461,14 @@ export class NocturneSdk {

async prepareOperation(
{ request, meta }: OperationRequestWithMetadata,
batchPreference: SelectedBatchPreference,
{ batchPreference, eoaProvidesGas }: PrepareOperationOpts,
): Promise<OpWithMetadata<PreSignOperation>> {
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,
Expand Down Expand Up @@ -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<PreSignOperation>): Promise<ContractTransaction> {
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,
Expand Down Expand Up @@ -545,26 +564,26 @@ export class NocturneSdk {
erc20Address: Address,
amount: bigint,
recipientAddress: Address,
batchPreference: SelectedBatchPreference,
opts: PrepareOperationOpts,
): Promise<OpWithMetadata<PreSignOperation>> {
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<OpWithMetadata<PreSignOperation>> {
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({
Expand All @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions packages/frontend-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fa234de

Please sign in to comment.