Skip to content

Commit

Permalink
fix: send approve tx
Browse files Browse the repository at this point in the history
  • Loading branch information
thelazyindian committed Jun 8, 2024
1 parent 3bfadb3 commit 6c16071
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 89 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/node_modules/**": true
}
}
15 changes: 12 additions & 3 deletions packages/adapters/orderbook-db/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import mongoose from "mongoose";

/// Order Schema
/// TODO: amounts, dapps, signatures, stratrgyType need to be in a object[]
interface MetaTransactionData {
to: string;
value: string;
data: string;
}
interface IOrder {
id: string;
signer: string; // signer address
Expand All @@ -14,7 +19,7 @@ interface IOrder {
dapps: string[];
distribution?: boolean;
amounts: string[];
signatures?: string[];
signatures?: MetaTransactionData[];
status: "P" | "E" | "C"; // Pending, Executed, Canceled
hashes?: string[]; // Optional array of transaction hashes
strategyType: "FLEXI" | "FIXED";
Expand All @@ -30,9 +35,13 @@ const OrderSchema = new mongoose.Schema<IOrder>({
cancelled: { type: Date }
},
dapps: [{ type: String, required: true }],
distribution: { type: Boolean, required: true },
distribution: { type: Boolean, required: false },
amounts: [{ type: String, required: true }],
signatures: [{ type: String, required: true }],
signatures: [{
to: { type: String, required: true },
value: { type: String, required: true },
data: { type: String, required: true }
}],
status: { type: String, enum: ["P", "E", "C"], required: true },
hashes: [{ type: String }],
strategyType: { type: String, enum: ["FLEXI", "FIXED"], required: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@ import { ApiProperty } from '@nestjs/swagger';
import { IsIn, IsNotEmpty, IsString, Length } from 'class-validator';
import { MetaTransactionData } from '@safe-global/safe-core-sdk-types';
import { NovaResponse } from 'src/common/interfaces/nova-response.interface';
import { TransactionRequest, TypedDataEncoder } from 'ethers';

export class OrderbookGetApproveTxQueryDto {
@IsString()
@IsNotEmpty()
@Length(42, 42)
@ApiProperty({
description: 'The asset address',
example: '0x0617b72940f105811F251967EE4fdD5E38f159d5',
description: 'Asset address',
example: '0x83A9aE82b26249EC6e01498F5aDf0Ec20fF3Da9C',
})
assetAddress: string;

@IsString()
@IsNotEmpty()
@Length(42, 42)
@ApiProperty({
description: 'User SCW address',
example: '0xC7E0F1883aD6DABBA9a6a440beeBD2Bfe4851758',
})
walletAddress: string;


@IsString()
@IsNotEmpty()
@ApiProperty({
description: 'The amount of token to be approved',
example: '10000000',
example: '1000000',
})
amount: string;
}
Expand All @@ -28,25 +38,30 @@ export class OrderbookSendApproveTxQueryDto {
@IsNotEmpty()
@Length(42, 42)
@ApiProperty({
description: 'The user wallet address',
description: 'User\'s EOA Address',
example: '0x0617b72940f105811F251967EE4fdD5E38f159d5',
})
userWalletAddress: string;
signerAddress: string;

@IsString()
@IsNotEmpty()
@Length(42, 42)
@ApiProperty({
description: 'The user scw address',
description: 'User\'s Safe Wallet Address',
example: '0x0617b72940f105811F251967EE4fdD5E38f159d5',
})
userScwAddress: string;
walletAddress: string;

@ApiProperty({
description: 'Meta transation data received from get approve tx',
})
metaTransaction: MetaTransactionData;

@IsNotEmpty()
@ApiProperty({
description: 'The signed tx',
})
userSignedTransaction: MetaTransactionData;
signature: string;

@IsIn(['FLEXI', 'FIXED'])
@IsNotEmpty()
Expand All @@ -58,24 +73,29 @@ export class OrderbookSendApproveTxQueryDto {

@IsString()
@IsNotEmpty()
@Length(42, 42)
@ApiProperty({
description: 'The amount of token to be approved',
example: '10000000',
example: '1000000',
})
amount: string;
}

export class ApyResponse {
@IsString()
@IsNotEmpty()
apy: string;
export class OrderbookGetApproveTxDataDto {
@ApiProperty({
description: 'Raw Transaction Metadata',
})
txData: MetaTransactionData;
@ApiProperty({
description: 'Json Typed Data to be signed',
example: '{...}',
})
typedData: string;
}

export class OrderbookGetApproveTxResponseDto implements NovaResponse {
@ApiProperty({
description: 'Response message',
example: 'Apy data fetched successfully.',
example: 'Approve transaction created successfully.',
})
message: string;
@ApiProperty({
Expand All @@ -86,18 +106,22 @@ export class OrderbookGetApproveTxResponseDto implements NovaResponse {
@ApiProperty({
description: 'Response data',
})
data: ApyResponse;
data: OrderbookGetApproveTxDataDto;
}

export class OrderbookSendResponseDto {
@ApiProperty({
description: 'Response message',
example: 'Apy data fetched successfully.',
example: 'Transaction submitted successfully.',
})
message: string;
@ApiProperty({
description: 'Response status code',
example: 201,
})
statusCode: number;
@ApiProperty({
description: 'Gelato relayer task data',
})
data: { taskId: string };
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Controller, Get, HttpCode, HttpStatus, Query } from '@nestjs/common';
import { Body, Controller, Get, HttpCode, HttpStatus, Post, Query } from '@nestjs/common';
import { ApiResponse, ApiTags } from '@nestjs/swagger';
import { OrderbookGetApproveTxQueryDto, OrderbookSendApproveTxQueryDto, OrderbookSendResponseDto } from './dto/approve.dto';
import { OrderbookGetApproveTxDataDto, OrderbookGetApproveTxQueryDto, OrderbookGetApproveTxResponseDto, OrderbookSendApproveTxQueryDto, OrderbookSendResponseDto } from './dto/approve.dto';
import { OrderbookService } from './orderbook.service';
import { ethers } from 'ethers';
import { Post } from '@nestjs/common';
import { Body } from '@nestjs/common';

@ApiTags('orderbook')
@Controller('orderbook')
Expand All @@ -20,12 +17,12 @@ export class OrderbookController {
@ApiResponse({
status: HttpStatus.OK,
description: 'Get transaction for approve',
type: OrderbookGetApproveTxQueryDto,
type: OrderbookGetApproveTxResponseDto,
})
@Get('create-approve')
createApproveTransaction(
@Query() query: OrderbookGetApproveTxQueryDto,
): Promise<ethers.TransactionRequest> {
): Promise<OrderbookGetApproveTxDataDto> {
return this.orderbookService.createApproveTransaction(query);
}

Expand All @@ -40,7 +37,7 @@ export class OrderbookController {
type: OrderbookSendResponseDto,
})
@Post('send-approve')
async sendApprove(@Body() body: OrderbookSendApproveTxQueryDto): Promise<void> {
async sendApprove(@Body() body: OrderbookSendApproveTxQueryDto): Promise<{ taskId: string }> {
return await this.orderbookService.sendApproveTransaction(body);
}

Expand Down
Loading

0 comments on commit 6c16071

Please sign in to comment.