Skip to content

Commit

Permalink
Merge pull request #289 from convergence-rfq/vault-operator
Browse files Browse the repository at this point in the history
Vault operator minor api changes
  • Loading branch information
pindaroso authored Mar 26, 2024
2 parents 9933d94 + c5ed27e commit 8a74598
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
8 changes: 8 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @convergence-rfq/cli

## 6.4.2

### Patch Changes

- Update some of vault operator actions API
- Updated dependencies
- @convergence-rfq/sdk@6.4.2

## 6.4.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@convergence-rfq/cli",
"description": "Official Convergence CLI",
"version": "6.4.1",
"version": "6.4.2",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -47,7 +47,7 @@
"cli": "ts-node src/index.ts"
},
"dependencies": {
"@convergence-rfq/sdk": "6.4.1",
"@convergence-rfq/sdk": "6.4.2",
"@solana/web3.js": "^1.87.6",
"@types/cookie": "^0.5.1",
"commander": "^10.0.0"
Expand Down
6 changes: 6 additions & 0 deletions packages/js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @convergence-rfq/sdk

## 6.4.2

### Patch Changes

- Update some of vault operator actions API

## 6.4.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@convergence-rfq/sdk",
"description": "Official Convergence RFQ SDK",
"version": "6.4.1",
"version": "6.4.2",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type ConfirmAndPrepareVaultInput = {

export type ConfirmAndPrepareVaultOutput = {
response: SendAndConfirmTransactionResponse;
vault: VaultParameters;
};

export const confirmAndPrepareVaultOperationHandler: OperationHandler<ConfirmAndPrepareVaultOperation> =
Expand All @@ -52,7 +53,7 @@ export const confirmAndPrepareVaultOperationHandler: OperationHandler<ConfirmAnd
cvg: Convergence,
scope: OperationScope
) => {
const builder = await confirmAndPrepareVaultBuilder(
const { builder, vault } = await confirmAndPrepareVaultBuilder(
cvg,
operation.input,
scope
Expand All @@ -62,17 +63,22 @@ export const confirmAndPrepareVaultOperationHandler: OperationHandler<ConfirmAnd

scope.throwIfCanceled();

return output;
return { ...output, vault };
},
};

export type ConfirmAndPrepareVaultBuilderParams = ConfirmAndPrepareVaultInput;

export type ConfirmAndPrepareVaultResult = {
builder: TransactionBuilder;
vault: VaultParameters;
};

export const confirmAndPrepareVaultBuilder = async (
cvg: Convergence,
params: ConfirmAndPrepareVaultBuilderParams,
options: TransactionBuilderOptions = {}
): Promise<TransactionBuilder> => {
): Promise<ConfirmAndPrepareVaultResult> => {
const { programs, payer = cvg.rpc().getDefaultFeePayer() } = options;
const { vault, rfq, response } = params;

Expand Down Expand Up @@ -151,8 +157,16 @@ export const confirmAndPrepareVaultBuilder = async (
key: 'prepareVaultSettlement',
};

return TransactionBuilder.make()
const builder = TransactionBuilder.make()
.setFeePayer(payer)
.addTxPriorityFeeIx(cvg)
.add(confirmIx, prepareIx);

return {
builder,
vault: {
...vault,
confirmedResponse: response.address,
},
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createWithdrawTokensInstruction } from '@convergence-rfq/vault-operator';
import { PublicKey } from '@solana/web3.js';
import { SendAndConfirmTransactionResponse } from '../../rpcModule';

import { Convergence } from '../../../Convergence';
Expand All @@ -14,7 +13,7 @@ import {
TransactionBuilderOptions,
} from '../../../utils/TransactionBuilder';
import { VaultParameters } from '../models';
import { EscrowResponse, EscrowRfq } from '@/plugins/rfqModule';
import { EscrowRfq } from '@/plugins/rfqModule';

const Key = 'WithdrawVaultTokensOperation' as const;

Expand All @@ -30,7 +29,6 @@ export type WithdrawVaultTokensOperation = Operation<
export type WithdrawVaultTokensInput = {
vault: VaultParameters;
rfq: EscrowRfq;
response?: EscrowResponse;
};

export type WithdrawVaultTokensOutput = {
Expand Down Expand Up @@ -66,14 +64,11 @@ export const withdrawVaultTokensBuilder = async (
options: TransactionBuilderOptions = {}
): Promise<TransactionBuilder> => {
const { programs, payer = cvg.rpc().getDefaultFeePayer() } = options;
const { vault, rfq, response } = params;
const { vault, rfq } = params;

if (!vault.rfq.equals(rfq.address)) {
throw new Error('RFQ does not match the provided vault');
}
if (response !== undefined && !response.rfq.equals(rfq.address)) {
throw new Error('RFQ does not match the provided response');
}

const vaultProgram = cvg.programs().getVaultOperator(programs).address;
const operator = cvg.vaultOperator().pdas().operator(vault.address);
Expand Down Expand Up @@ -105,7 +100,7 @@ export const withdrawVaultTokensBuilder = async (
.pdas()
.associatedTokenAccount({ mint: quoteMint, owner: vault.creator }),
quoteMint,
response: response?.address ?? PublicKey.default,
response: vault.confirmedResponse,
},
vaultProgram
),
Expand Down
22 changes: 14 additions & 8 deletions packages/js/tests/integration/vaultOperator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('integration.vaultOperator', () => {
const { rfqResponse: response } = await makerCvg
.rfqs()
.respond({ rfq: rfq.address, bid: { price: responsePrice } });
await executorCvg
const { vault: updatedVault } = await executorCvg
.vaultOperator()
.confirmAndPrepare({ vault, rfq, response });
await makerCvg.rfqs().prepareSettlement({
Expand All @@ -67,7 +67,9 @@ describe('integration.vaultOperator', () => {
});
await executorCvg.rfqs().cleanUpResponse({ response: response.address });

await executorCvg.vaultOperator().withdrawTokens({ vault, rfq, response });
await executorCvg
.vaultOperator()
.withdrawTokens({ vault: updatedVault, rfq });

const [takerBtcAfter, takerQuoteAfter] = await Promise.all([
fetchTokenAmount(takerCvg, baseMintBTC.address),
Expand Down Expand Up @@ -108,7 +110,7 @@ describe('integration.vaultOperator', () => {
const { rfqResponse: response } = await makerCvg
.rfqs()
.respond({ rfq: rfq.address, ask: { price: responsePrice } });
await executorCvg
const { vault: updatedVault } = await executorCvg
.vaultOperator()
.confirmAndPrepare({ vault, rfq, response });
await makerCvg.rfqs().prepareSettlement({
Expand All @@ -121,7 +123,9 @@ describe('integration.vaultOperator', () => {
});
await executorCvg.rfqs().cleanUpResponse({ response: response.address });

await executorCvg.vaultOperator().withdrawTokens({ vault, rfq, response });
await executorCvg
.vaultOperator()
.withdrawTokens({ vault: updatedVault, rfq });

const [takerBtcAfter, takerQuoteAfter] = await Promise.all([
fetchTokenAmount(takerCvg, baseMintBTC.address),
Expand Down Expand Up @@ -156,15 +160,15 @@ describe('integration.vaultOperator', () => {
.vaultOperator()
.findByAddress({ address: vaultAddress });

const response = await runInParallelWithWait(async () => {
const [response, updatedVault] = await runInParallelWithWait(async () => {
const { rfqResponse: response } = await makerCvg
.rfqs()
.respond({ rfq: rfq.address, ask: { price: 40000 } });
await executorCvg
const { vault: updatedVault } = await executorCvg
.vaultOperator()
.confirmAndPrepare({ vault, rfq, response });

return response;
return [response, updatedVault];
}, 3.5);

await executorCvg.rfqs().revertSettlementPreparation({
Expand All @@ -173,7 +177,9 @@ describe('integration.vaultOperator', () => {
});
await executorCvg.rfqs().cleanUpResponse({ response: response.address });

await executorCvg.vaultOperator().withdrawTokens({ vault, rfq, response });
await executorCvg
.vaultOperator()
.withdrawTokens({ vault: updatedVault, rfq });

const [takerBtcAfter, takerQuoteAfter] = await Promise.all([
fetchTokenAmount(takerCvg, baseMintBTC.address),
Expand Down

0 comments on commit 8a74598

Please sign in to comment.