From 00663fe567ec375b9efd602ed183ee9e3936d11e Mon Sep 17 00:00:00 2001 From: pedromcunha Date: Tue, 28 May 2024 14:32:21 -0400 Subject: [PATCH] Upgrade to v2 or call/bridge actions --- packages/sdk/src/actions/bridge.ts | 24 ++++++++++++++---------- packages/sdk/src/actions/call.ts | 18 +++++++----------- packages/sdk/src/actions/swap.ts | 11 ++++------- packages/sdk/src/types/Execute.ts | 10 ++++------ packages/sdk/src/types/api.ts | 2 ++ 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/packages/sdk/src/actions/bridge.ts b/packages/sdk/src/actions/bridge.ts index ff933093..102ce0fc 100644 --- a/packages/sdk/src/actions/bridge.ts +++ b/packages/sdk/src/actions/bridge.ts @@ -1,4 +1,9 @@ -import type { Execute, AdaptedWallet, paths, CallFees } from '../types/index.js' +import type { + Execute, + AdaptedWallet, + paths, + ProgressData +} from '../types/index.js' import { APIError, adaptViemWallet, @@ -10,10 +15,9 @@ import { isViemWalletClient } from '../utils/viemWallet.js' import { getClient } from '../client.js' import type { AxiosRequestConfig } from 'axios' import axios from 'axios' -import type { CallProgressData } from './call.js' export type BridgeBody = NonNullable< - paths['/execute/bridge']['post']['requestBody']['content']['application/json'] + paths['/execute/bridge/v2']['post']['requestBody']['content']['application/json'] > export type BridgeBodyOptions = Omit< BridgeBody, @@ -33,7 +37,7 @@ export type BridgeActionParameters = { recipient?: Address options?: BridgeBodyOptions depositGasLimit?: string - onProgress?: (data: CallProgressData) => any + onProgress?: (data: ProgressData) => any } & ( | { precheck: true; wallet?: AdaptedWallet | WalletClient } // When precheck is true, wallet is optional | { precheck?: false; wallet: AdaptedWallet | WalletClient } @@ -100,7 +104,7 @@ export async function bridge(data: BridgeActionParameters) { } const request: AxiosRequestConfig = { - url: `${client.baseApiUrl}/execute/bridge`, + url: `${client.baseApiUrl}/execute/bridge/v2`, method: 'post', data } @@ -109,10 +113,10 @@ export async function bridge(data: BridgeActionParameters) { const res = await axios.request(request) if (res.status !== 200) throw new APIError(res?.data?.message, res.status, res.data) - const data = res.data as Omit & { fees: CallFees } + const data = res.data as Execute onProgress({ steps: data['steps'], - fees: data['fees'] as CallFees, + fees: data['fees'], breakdown: data['breakdown'] }) return data @@ -121,7 +125,7 @@ export async function bridge(data: BridgeActionParameters) { throw new Error('AdaptedWallet is required to execute steps') } - return (await executeSteps( + return await executeSteps( chainId, request, adaptedWallet, @@ -131,7 +135,7 @@ export async function bridge(data: BridgeActionParameters) { onProgress({ steps, - fees: fees as CallFees, + fees, breakdown, currentStep, currentStepItem, @@ -146,7 +150,7 @@ export async function bridge(data: BridgeActionParameters) { } } : undefined - )) as Omit & { fees: CallFees } + ) } } catch (err: any) { console.error(err) diff --git a/packages/sdk/src/actions/call.ts b/packages/sdk/src/actions/call.ts index c1b6f239..a855060c 100644 --- a/packages/sdk/src/actions/call.ts +++ b/packages/sdk/src/actions/call.ts @@ -23,17 +23,13 @@ import { import { isViemWalletClient } from '../utils/viemWallet.js' export type CallBody = NonNullable< - paths['/execute/call']['post']['requestBody']['content']['application/json'] + paths['/execute/call/v2']['post']['requestBody']['content']['application/json'] > export type CallBodyOptions = Omit< CallBody, 'txs' | 'destinationChainId' | 'originChainId' > -export type CallProgressData = Omit & { - fees: CallFees -} - export type SimulateContractRequest = WriteContractParameters export type CallActionParameters = { @@ -42,7 +38,7 @@ export type CallActionParameters = { toChainId: number options?: Omit depositGasLimit?: string - onProgress?: (data: CallProgressData) => any + onProgress?: (data: ProgressData) => any } & ( | { precheck: true; wallet?: AdaptedWallet | WalletClient } // When precheck is true, wallet is optional | { precheck?: false; wallet: AdaptedWallet | WalletClient } @@ -118,7 +114,7 @@ export async function call(data: CallActionParameters) { } const request: AxiosRequestConfig = { - url: `${client.baseApiUrl}/execute/call`, + url: `${client.baseApiUrl}/execute/call/v2`, method: 'post', data } @@ -127,7 +123,7 @@ export async function call(data: CallActionParameters) { const res = await axios.request(request) if (res.status !== 200) throw new APIError(res?.data?.message, res.status, res.data) - const data = res.data as Omit & { fees: CallFees } + const data = res.data as Execute onProgress({ steps: data['steps'], fees: data['fees'] as CallFees, @@ -139,7 +135,7 @@ export async function call(data: CallActionParameters) { throw new Error('AdaptedWallet is required to execute steps') } - return (await executeSteps( + return await executeSteps( chainId, request, adaptedWallet, @@ -149,7 +145,7 @@ export async function call(data: CallActionParameters) { onProgress({ steps, - fees: fees as CallFees, + fees, breakdown, currentStep, currentStepItem, @@ -164,7 +160,7 @@ export async function call(data: CallActionParameters) { } } : undefined - )) as Omit & { fees: CallFees } + ) } } catch (err: any) { console.error(err) diff --git a/packages/sdk/src/actions/swap.ts b/packages/sdk/src/actions/swap.ts index d6d0bcd0..18e08fb8 100644 --- a/packages/sdk/src/actions/swap.ts +++ b/packages/sdk/src/actions/swap.ts @@ -2,8 +2,7 @@ import type { Execute, paths, AdaptedWallet, - ProgressData, - SwapFees + ProgressData } from '../types/index.js' import { getClient } from '../client.js' import { @@ -36,9 +35,7 @@ export type SwapBodyOptions = Omit< | 'recipient' > -type SwapProgressData = Omit & { - fees: SwapFees -} +type SwapProgressData = ProgressData export type SwapActionParameters = { chainId: number @@ -142,7 +139,7 @@ export async function swap(data: SwapActionParameters) { const data = res.data as Execute onProgress({ steps: data['steps'], - fees: data['fees'] as SwapFees, + fees: data['fees'], breakdown: data['breakdown'], details: data['details'] }) @@ -162,7 +159,7 @@ export async function swap(data: SwapActionParameters) { onProgress({ steps, - fees: fees as SwapFees, + fees, breakdown, details, currentStep, diff --git a/packages/sdk/src/types/Execute.ts b/packages/sdk/src/types/Execute.ts index fa6f7391..523228de 100644 --- a/packages/sdk/src/types/Execute.ts +++ b/packages/sdk/src/types/Execute.ts @@ -2,14 +2,12 @@ import type { Address } from 'viem' import type { paths } from './api.js' export type CallFees = - paths['/execute/call']['post']['responses']['200']['content']['application/json']['fees'] -export type SwapFees = - paths['/execute/swap']['post']['responses']['200']['content']['application/json']['fees'] + paths['/execute/call/v2']['post']['responses']['200']['content']['application/json']['fees'] export type CallBreakdown = - paths['/execute/call']['post']['responses']['200']['content']['application/json']['breakdown'] + paths['/execute/call/v2']['post']['responses']['200']['content']['application/json']['breakdown'] export type CheckApi = NonNullable< NonNullable< - paths['/execute/call']['post']['responses']['200']['content']['application/json']['steps'] + paths['/execute/call/v2']['post']['responses']['200']['content']['application/json']['steps'] >['0']['items'] >[0]['check'] export type ExecuteDetails = NonNullable< @@ -25,7 +23,7 @@ export type SignatureStepState = export type Execute = { errors?: { message?: string; orderId?: string }[] - fees?: CallFees | SwapFees + fees?: CallFees breakdown?: CallBreakdown details?: ExecuteDetails error?: any // Manually added client error diff --git a/packages/sdk/src/types/api.ts b/packages/sdk/src/types/api.ts index 2b6f2a41..9a7aad0b 100644 --- a/packages/sdk/src/types/api.ts +++ b/packages/sdk/src/types/api.ts @@ -2329,8 +2329,10 @@ export interface paths { 200: { content: { "application/json": { + AVAX?: number; ETH?: number; DEGEN?: number; + MATIC?: number; USDC?: number; XAI?: number; };