Fix autoswap
This commit is contained in:
@@ -180,14 +180,20 @@ async function init () {
|
||||
}
|
||||
}
|
||||
|
||||
// Store the request ID for later use
|
||||
request.idempotencyKey = requestId as string
|
||||
// Store the request ID for later use using a symbol to avoid TypeScript property errors
|
||||
const IDEMPOTENCY_KEY_SYMBOL = Symbol.for('idempotency-key')
|
||||
// Attach the symbol to the request object
|
||||
;(request as any)[IDEMPOTENCY_KEY_SYMBOL] = requestId as string
|
||||
|
||||
})
|
||||
|
||||
// Add post-handler hook to store successful responses
|
||||
app.addHook('onSend', async (request, reply, payload) => {
|
||||
if (request.idempotencyKey && request.method === 'POST') {
|
||||
const requestId = request.idempotencyKey
|
||||
// Retrieve the idempotency key from the symbol
|
||||
const IDEMPOTENCY_KEY_SYMBOL = Symbol.for('idempotency-key')
|
||||
const idempotencyKey = (request as any)[IDEMPOTENCY_KEY_SYMBOL]
|
||||
if (idempotencyKey && request.method === 'POST') {
|
||||
const requestId = idempotencyKey
|
||||
|
||||
// Only store successful responses (2xx status codes)
|
||||
if (reply.statusCode >= 200 && reply.statusCode < 300) {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
declare module 'fastify' {
|
||||
interface FastifyRequest {
|
||||
idempotencyKey?: string
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,15 @@ describe('swap tokens implementation', () => {
|
||||
|
||||
it('should swap SOL to USDC successfully', async () => {
|
||||
try {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f'
|
||||
const testAccount = '0x932167388dD9aad41149b3cA23eBD489E2E2DD78'
|
||||
const sdk = await getClientForAddress(testAccount)
|
||||
|
||||
console.log('Account', sdk.account)
|
||||
const result = await swapGmxTokensImpl(
|
||||
sdk,
|
||||
Ticker.PENDLE,
|
||||
Ticker.ETH,
|
||||
Ticker.USDC,
|
||||
13.339559522
|
||||
0.0042
|
||||
)
|
||||
|
||||
assert.strictEqual(typeof result, 'string')
|
||||
|
||||
Reference in New Issue
Block a user