Skip to content

Commit b360000

Browse files
authored
docs: re-gen typedoc + README updates (#244)
1 parent 309e427 commit b360000

File tree

145 files changed

+4213
-2885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+4213
-2885
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ const client = createAcrossClient({
5050
chains: [mainnet, optimism, arbitrum],
5151
});
5252

53-
// 2. Retrieve quote for USDC from Arbitrum -> Optimism
53+
// 2. Retrieve quote for USDC from Arbitrum -> ETH on Optimism
5454
const route = {
5555
originChainId: arbitrum.id,
5656
destinationChainId: optimism.id,
57-
inputToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
58-
outputToken: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
57+
inputToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
58+
outputToken: "0x0000000000000000000000000000000000000000", // Native ETH
5959
};
60-
const quote = await client.getQuote({
60+
const swapQuote = await client.getSwapQuote({
6161
route,
62-
inputAmount: parseUnit("1000", 6) // USDC decimals
63-
})
62+
amount: parseUnit("10", 6), // USDC decimals
63+
});
6464

6565
// 3. Execute quote
66-
await client.executeQuote({
66+
await client.executeSwapQuote({
6767
walletClient: wallet,
68-
deposit: quote.deposit,
68+
swapQuote,
6969
onProgress: (progress) => {
7070
// handle progress
7171
},

packages/sdk/README.md

Lines changed: 48 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ const client = createAcrossClient({
6262

6363
### 2. Retrieve a quote
6464

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.
6666

6767
```ts
6868
import { parseEther } from "viem";
6969

70-
// WETH from Arbitrum -> Optimism
70+
// USDC from Arbitrum -> ETH on Optimism
7171
const route = {
7272
originChainId: arbitrum.id,
7373
destinationChainId: optimism.id,
74-
inputToken: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", // WETH arb
75-
outputToken: "0x4200000000000000000000000000000000000006", // WETH opt
74+
inputToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
75+
outputToken: "0x0000000000000000000000000000000000000000", // Native ETH
7676
};
7777

78-
const quote = await client.getQuote({
78+
const swapQuote = await client.getSwapQuote({
7979
route,
80-
inputAmount: parseEther("1"),
80+
amount: parseUnit("10", 6), // USDC decimals
8181
});
8282
```
8383

@@ -93,9 +93,9 @@ import { useWalletClient } from "wagmi";
9393

9494
const wallet = useWalletClient();
9595

96-
await client.executeQuote({
96+
await client.executeSwapQuote({
9797
walletClient: wallet,
98-
deposit: quote.deposit, // returned by `getQuote`
98+
swapQuote, // returned by `client.getSwapQuote`
9999
onProgress: (progress) => {
100100
if (progress.step === "approve" && progress.status === "txSuccess") {
101101
// if approving an ERC20, you have access to the approval receipt
@@ -116,8 +116,8 @@ await client.executeQuote({
116116

117117
The method will execute a quote by:
118118

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)
121121
3. Waiting for the deposit to be filled on the destination chain
122122

123123
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
129129

130130
### Example: Stake Native ETH on Destination Chain
131131

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.
141134

142135
```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";
215139

216-
### 2. Retrieve a quote
140+
const wallet = useWalletClient();
217141

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";
219144

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
221152
const route = {
222153
originChainId: arbitrum.id,
223154
destinationChainId: optimism.id,
224-
inputToken: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", // WETH arbitrum
225-
outputToken: "0x4200000000000000000000000000000000000006", // WETH optimism
155+
inputToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
156+
outputToken: "0x0000000000000000000000000000000000000000", // Native ETH
226157
};
227-
228-
const quote = await client.getQuote({
158+
const swapQuote = await client.getSwapQuote({
229159
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+
],
234173
});
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();
245174

246-
await client.executeQuote({
175+
// 3. Execute quote
176+
await client.executeSwapQuote({
247177
walletClient: wallet,
248-
deposit: quote.deposit, // returned by `getQuote`
178+
swapQuote,
249179
onProgress: (progress) => {
250180
// handle progress
251181
},
@@ -277,17 +207,16 @@ For the full detailed reference see [here](./docs/README.md).
277207

278208
### Chains and Routes
279209

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)
282212

283213
### Quotes, Fees and Limits
284214

285-
- [`getQuote`](./docs/classes/AcrossClient.md#getquote)
215+
- [`getSwapQuote`](./docs/classes/AcrossClient.md#getswapquote)
286216

287217
### Transaction Simulations and Executions
288218

289-
- [`executeQuote`](./docs/classes/AcrossClient.md#executequote)
290-
- [`simulateDepositTx`](./docs/classes/AcrossClient.md#simulatedeposittx)
219+
- [`executeSwapQuote`](./docs/classes/AcrossClient.md#executeswapquote)
291220

292221
### Deposit and Fill Status
293222

packages/sdk/docs/README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- [AcrossChain](type-aliases/AcrossChain.md)
2020
- [AcrossClientOptions](type-aliases/AcrossClientOptions.md)
2121
- [AcrossErrorCodeType](type-aliases/AcrossErrorCodeType.md)
22+
- [Action](type-aliases/Action.md)
23+
- [ActionArg](type-aliases/ActionArg.md)
2224
- [Amount](type-aliases/Amount.md)
2325
- [BuildMessageParams](type-aliases/BuildMessageParams.md)
2426
- [ChainInfoMap](type-aliases/ChainInfoMap.md)
@@ -32,6 +34,9 @@
3234
- [DepositLog](type-aliases/DepositLog.md)
3335
- [DepositStatus](type-aliases/DepositStatus.md)
3436
- [ExecuteQuoteParams](type-aliases/ExecuteQuoteParams.md)
37+
- [ExecuteQuoteResponseParams](type-aliases/ExecuteQuoteResponseParams.md)
38+
- [ExecuteSwapQuoteParams](type-aliases/ExecuteSwapQuoteParams.md)
39+
- [ExecuteSwapQuoteResponseParams](type-aliases/ExecuteSwapQuoteResponseParams.md)
3540
- [ExecutionProgress](type-aliases/ExecutionProgress.md)
3641
- [FilledV3RelayEvent](type-aliases/FilledV3RelayEvent.md)
3742
- [FillEventLog](type-aliases/FillEventLog.md)
@@ -49,12 +54,18 @@
4954
- [GetSuggestedFeesParams](type-aliases/GetSuggestedFeesParams.md)
5055
- [GetSuggestedFeesReturnType](type-aliases/GetSuggestedFeesReturnType.md)
5156
- [GetSupportedChainsParams](type-aliases/GetSupportedChainsParams.md)
57+
- [GetSwapChainsParams](type-aliases/GetSwapChainsParams.md)
58+
- [GetSwapChainsReturnType](type-aliases/GetSwapChainsReturnType.md)
59+
- [GetSwapQuoteParams](type-aliases/GetSwapQuoteParams.md)
60+
- [GetSwapTokensParams](type-aliases/GetSwapTokensParams.md)
61+
- [GetSwapTokensReturnType](type-aliases/GetSwapTokensReturnType.md)
5262
- [IndexerStatusResponse](type-aliases/IndexerStatusResponse.md)
5363
- [LoggerT](type-aliases/LoggerT.md)
5464
- [LogLevel](type-aliases/LogLevel.md)
5565
- [MakeOptional](type-aliases/MakeOptional.md)
5666
- [NoNullValuesOfObject](type-aliases/NoNullValuesOfObject.md)
5767
- [Quote](type-aliases/Quote.md)
68+
- [RecursiveActionArg](type-aliases/RecursiveActionArg.md)
5869
- [Route](type-aliases/Route.md)
5970
- [RoutesQueryParams](type-aliases/RoutesQueryParams.md)
6071
- [SignUpdateDepositTypedDataParams](type-aliases/SignUpdateDepositTypedDataParams.md)
@@ -63,7 +74,10 @@
6374
- [SimulateUpdateDepositTxParams](type-aliases/SimulateUpdateDepositTxParams.md)
6475
- [Status](type-aliases/Status.md)
6576
- [SuggestedFeesQueryParams](type-aliases/SuggestedFeesQueryParams.md)
66-
- [SuggestedFeesResponse](type-aliases/SuggestedFeesResponse.md)
77+
- [SwapApiToken](type-aliases/SwapApiToken.md)
78+
- [SwapChain](type-aliases/SwapChain.md)
79+
- [SwapChainsQueryParams](type-aliases/SwapChainsQueryParams.md)
80+
- [SwapExecutionProgress](type-aliases/SwapExecutionProgress.md)
6781
- [TenderlySimulateTxParams](type-aliases/TenderlySimulateTxParams.md)
6882
- [TokenInfo](type-aliases/TokenInfo.md)
6983
- [TransactionProgress](type-aliases/TransactionProgress.md)
@@ -76,9 +90,13 @@
7690
## Variables
7791

7892
- [DOMAIN\_CALLDATA\_DELIMITER](variables/DOMAIN_CALLDATA_DELIMITER.md)
93+
- [fetchAcrossApi](variables/fetchAcrossApi.md)
94+
- [fetchAcrossApiPost](variables/fetchAcrossApiPost.md)
95+
- [fetchIndexerApi](variables/fetchIndexerApi.md)
7996
- [FillType](variables/FillType.md)
8097
- [LogLevels](variables/LogLevels.md)
8198
- [MulticallHandlerAbi](variables/MulticallHandlerAbi.md)
99+
- [ZERO\_BYTES\_32](variables/ZERO_BYTES_32.md)
82100

83101
## Functions
84102

@@ -90,8 +108,7 @@
90108
- [configurePublicClients](functions/configurePublicClients.md)
91109
- [createAcrossClient](functions/createAcrossClient.md)
92110
- [executeQuote](functions/executeQuote.md)
93-
- [fetchAcrossApi](functions/fetchAcrossApi.md)
94-
- [fetchIndexerApi](functions/fetchIndexerApi.md)
111+
- [executeSwapQuote](functions/executeSwapQuote.md)
95112
- [getAcrossClient](functions/getAcrossClient.md)
96113
- [getAvailableRoutes](functions/getAvailableRoutes.md)
97114
- [getCurrentTimeSeconds](functions/getCurrentTimeSeconds.md)
@@ -105,21 +122,27 @@
105122
- [getQuote](functions/getQuote.md)
106123
- [getSuggestedFees](functions/getSuggestedFees.md)
107124
- [getSupportedChains](functions/getSupportedChains.md)
125+
- [getSwapChains](functions/getSwapChains.md)
126+
- [getSwapQuote](functions/getSwapQuote.md)
127+
- [getSwapTokens](functions/getSwapTokens.md)
108128
- [getUpdateDepositTypedData](functions/getUpdateDepositTypedData.md)
109129
- [getUpdateDepositTypedDataV3\_5](functions/getUpdateDepositTypedDataV3_5.md)
130+
- [hasMessage](functions/hasMessage.md)
131+
- [isDefined](functions/isDefined.md)
110132
- [isOk](functions/isOk.md)
111133
- [isValidIntegratorId](functions/isValidIntegratorId.md)
112134
- [parseDepositLogs](functions/parseDepositLogs.md)
113135
- [parseFillLogs](functions/parseFillLogs.md)
136+
- [parseSuggestedFees](functions/parseSuggestedFees.md)
114137
- [signUpdateDepositTypedData](functions/signUpdateDepositTypedData.md)
138+
- [signUpdateDepositTypedDataV3\_5](functions/signUpdateDepositTypedDataV3_5.md)
115139
- [simulateApproveTx](functions/simulateApproveTx.md)
116140
- [simulateDepositTx](functions/simulateDepositTx.md)
117141
- [simulateTxOnTenderly](functions/simulateTxOnTenderly.md)
118142
- [simulateUpdateDepositTx](functions/simulateUpdateDepositTx.md)
119143
- [tagIntegratorId](functions/tagIntegratorId.md)
120144
- [waitForDepositTx](functions/waitForDepositTx.md)
121145
- [waitForFillByDepositTx](functions/waitForFillByDepositTx.md)
146+
- [waitForFillEvent](functions/waitForFillEvent.md)
122147
- [waitForFillTx](functions/waitForFillTx.md)
123148
- [waitForFillTxEvent](functions/waitForFillTxEvent.md)
124-
- [waitForV3\_5FillEvent](functions/waitForV3_5FillEvent.md)
125-
- [waitForV3FillEvent](functions/waitForV3FillEvent.md)

0 commit comments

Comments
 (0)