@@ -62,22 +62,22 @@ const client = createAcrossClient({
62
62
63
63
### 2. Retrieve a quote
64
64
65
- Now, you can retrieve a quote for a given route.
65
+ Now, you can retrieve a quote for a given route with an arbitrary token pair .
66
66
67
67
``` ts
68
68
import { parseEther } from " viem" ;
69
69
70
- // WETH from Arbitrum -> Optimism
70
+ // USDC from Arbitrum -> ETH on Optimism
71
71
const route = {
72
72
originChainId: arbitrum .id ,
73
73
destinationChainId: optimism .id ,
74
- inputToken: " 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 " , // WETH arb
75
- outputToken: " 0x4200000000000000000000000000000000000006 " , // WETH opt
74
+ inputToken: " 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 " , // USDC
75
+ outputToken: " 0x0000000000000000000000000000000000000000 " , // Native ETH
76
76
};
77
77
78
- const quote = await client .getQuote ({
78
+ const swapQuote = await client .getSwapQuote ({
79
79
route ,
80
- inputAmount: parseEther ( " 1 " ),
80
+ amount: parseUnit ( " 10 " , 6 ), // USDC decimals
81
81
});
82
82
```
83
83
@@ -93,9 +93,9 @@ import { useWalletClient } from "wagmi";
93
93
94
94
const wallet = useWalletClient ();
95
95
96
- await client .executeQuote ({
96
+ await client .executeSwapQuote ({
97
97
walletClient: wallet ,
98
- deposit: quote . deposit , // returned by `getQuote `
98
+ swapQuote , // returned by `client.getSwapQuote `
99
99
onProgress : (progress ) => {
100
100
if (progress .step === " approve" && progress .status === " txSuccess" ) {
101
101
// if approving an ERC20, you have access to the approval receipt
@@ -116,8 +116,8 @@ await client.executeQuote({
116
116
117
117
The method will execute a quote by:
118
118
119
- 1 . Approving the SpokePool contract if necessary
120
- 2 . Depositing the input token on the origin chain
119
+ 1 . Approving the ` SpokePool ` or ` SpokePoolPeriphery ` contract if necessary
120
+ 2 . Depositing the input token on the origin chain (also facilitating an origin swap if necessary)
121
121
3 . Waiting for the deposit to be filled on the destination chain
122
122
123
123
You can use the ` onProgress ` callback to act on different stages of the execution.
@@ -129,123 +129,53 @@ Across enables users to seamlessly interact with your dApp or chain using assets
129
129
130
130
### Example: Stake Native ETH on Destination Chain
131
131
132
- To stake native ETH in one step:
133
-
134
- 1 . Bridge WETH to the destination chain, sending the output tokens (WETH) to Across's MulticallHandler contract (since contracts receive WETH).
135
- 2 . Unwrap WETH to obtain native ETH.
136
- 3 . Stake the ETH on your staking contract.
137
-
138
- ** Note** : If your calldata depends on the output amount, you must use the ` update() ` function.
139
-
140
- ### 1. Craft a cross-chain message
132
+ This example shows you how to use the app-sdk to swap, bridge and stake native ETH across chains.
133
+ You only need to specify the destination chain actions.
141
134
142
135
``` ts
143
- import { type Amount } from " @across-protocol/app-sdk" ;
144
- import { encodeFunctionData } from " viem" ;
145
- import { optimism } from " viem/chains" ;
146
-
147
- // constants
148
- const userAddress = " 0xFoo" ;
149
- const multicallHandlerOptimism = " 0x924a9f036260DdD5808007E1AA95f08eD08aA569" ;
150
-
151
- export const WETH_OPTIMISM = {
152
- chain: optimism ,
153
- abi: WethAbi ,
154
- address: " 0x4200000000000000000000000000000000000006" ,
155
- decimals: 18 ,
156
- logoUrl:
157
- " https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/weth.svg" ,
158
- name: " Wrapped Ether" ,
159
- symbol: " WETH" ,
160
- } as const ;
161
-
162
- export const STAKE_CONTRACT = {
163
- address: " 0x733Debf51574c70CfCdb7918F032E16F686bd9f8" ,
164
- chain: optimism ,
165
- abi: StakerContractABI ,
166
- } as const ;
167
-
168
- // WETH unwrap action
169
- function generateUnwrapCallData(wethAmount : Amount ) {
170
- return encodeFunctionData ({
171
- abi: WETH_OPTIMISM .abi ,
172
- functionName: " withdraw" ,
173
- args: [BigInt (wethAmount )],
174
- });
175
- }
176
-
177
- // STAKE action
178
- function generateStakeCallData(userAddress : Address ) {
179
- return encodeFunctionData ({
180
- abi: STAKE_CONTRACT .abi ,
181
- functionName: " stake" ,
182
- args: [userAddress ],
183
- });
184
- }
185
-
186
- const unwrapAndStakeMessage = {
187
- actions: [
188
- {
189
- target: WETH_OPTIMISM .address ,
190
- callData: generateUnwrapCallData (inputAmount ),
191
- value: 0n ,
192
- // we only update the calldata since the unwrap call is non-payable, but we DO care about the output amount.
193
- update : (updatedOutputAmount ) => {
194
- return {
195
- callData: generateUnwrapCallData (updatedOutputAmount ),
196
- };
197
- },
198
- },
199
- {
200
- target: STAKE_CONTRACT .address ,
201
- callData: generateStakeCallData (userAddress ),
202
- // 🔔 the initial value may be set equal to the output amount. This MUST be updated via the `update()` function below oir this call will fail!
203
- value: inputAmount ,
204
- // now we MUST update msg.value since this last call is calling a payable function.
205
- update : (updatedOutputAmount ) => {
206
- return {
207
- value: updatedOutputAmount ,
208
- };
209
- },
210
- },
211
- ],
212
- fallbackRecipient: userAddress ,
213
- };
214
- ```
136
+ import { createAcrossClient } from " @across-protocol/app-sdk" ;
137
+ import { mainnet , optimism , arbitrum } from " viem/chains" ;
138
+ import { useWalletClient } from " wagmi" ;
215
139
216
- ### 2. Retrieve a quote
140
+ const wallet = useWalletClient ();
217
141
218
- After specifying a cross-chain message, you simply can fetch a quote the same way as a normal bridge
142
+ // Example Staking contract on OP
143
+ const stakingAddress = " 0x733Debf51574c70CfCdb7918F032E16F686bd9f8" ;
219
144
220
- ``` ts
145
+ // 1. Create client
146
+ const client = createAcrossClient ({
147
+ integratorId: " 0xdead" , // 2-byte hex string
148
+ chains: [mainnet , optimism , arbitrum ],
149
+ });
150
+
151
+ // 2. Retrieve quote for USDC from Arbitrum -> ETH on Optimism
221
152
const route = {
222
153
originChainId: arbitrum .id ,
223
154
destinationChainId: optimism .id ,
224
- inputToken: " 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 " , // WETH arbitrum
225
- outputToken: " 0x4200000000000000000000000000000000000006 " , // WETH optimism
155
+ inputToken: " 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 " , // USDC
156
+ outputToken: " 0x0000000000000000000000000000000000000000 " , // Native ETH
226
157
};
227
-
228
- const quote = await client .getQuote ({
158
+ const swapQuote = await client .getSwapQuote ({
229
159
route ,
230
- inputAmount: parseEther (" 1" ),
231
- // 🔔 Notice the recipient is not the staking contract itself or even the user, but the contract that will execute our cross chain messages
232
- recipient: multicallHandlerOptimism ,
233
- crossChainMessage: unwrapAndStakeMessage ,
160
+ amount: parseUnit (" 10" , 6 ), // USDC decimals
161
+ actions: [
162
+ {
163
+ // Target contract of destination chain actions
164
+ target: stakingAddress ,
165
+ // Human-readable ABI format of method to call
166
+ functionSignature: " function stake(address stakerAddress)" ,
167
+ // Args to above
168
+ args: [{ value: wallet .address }],
169
+ // Allows to set call value to available balance AFTER bridge
170
+ populateCallValueDynamically: true ,
171
+ },
172
+ ],
234
173
});
235
- ```
236
-
237
- ### 3. Execute a quote
238
-
239
- If the quote is available, you can execute like so
240
-
241
- ``` ts
242
- import { useWalletClient } from " wagmi" ;
243
-
244
- const wallet = useWalletClient ();
245
174
246
- await client .executeQuote ({
175
+ // 3. Execute quote
176
+ await client .executeSwapQuote ({
247
177
walletClient: wallet ,
248
- deposit: quote . deposit , // returned by `getQuote`
178
+ swapQuote ,
249
179
onProgress : (progress ) => {
250
180
// handle progress
251
181
},
@@ -277,17 +207,16 @@ For the full detailed reference see [here](./docs/README.md).
277
207
278
208
### Chains and Routes
279
209
280
- - [ ` getSupportedChains ` ] ( ./docs/classes/AcrossClient.md#getsupportedchains )
281
- - [ ` getAvailableRoutes ` ] ( ./docs/classes/AcrossClient.md#getavailableroutes )
210
+ - [ ` getSwapChains ` ] ( ./docs/classes/AcrossClient.md#getswapchains )
211
+ - [ ` getSwapTokens ` ] ( ./docs/classes/AcrossClient.md#getswaptokens )
282
212
283
213
### Quotes, Fees and Limits
284
214
285
- - [ ` getQuote ` ] ( ./docs/classes/AcrossClient.md#getquote )
215
+ - [ ` getSwapQuote ` ] ( ./docs/classes/AcrossClient.md#getswapquote )
286
216
287
217
### Transaction Simulations and Executions
288
218
289
- - [ ` executeQuote ` ] ( ./docs/classes/AcrossClient.md#executequote )
290
- - [ ` simulateDepositTx ` ] ( ./docs/classes/AcrossClient.md#simulatedeposittx )
219
+ - [ ` executeSwapQuote ` ] ( ./docs/classes/AcrossClient.md#executeswapquote )
291
220
292
221
### Deposit and Fill Status
293
222
0 commit comments