Skip to content

Commit 369309e

Browse files
committed
chore: update README & package version
1 parent a5aabc3 commit 369309e

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

README.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,40 @@ const poolKey = await uniDevKit.getPoolKeyFromPoolId({
125125
```
126126

127127
### `buildSwapCallData`
128-
Construct calldata and value for a Universal Router swap.
128+
Construct calldata for a Universal Router swap.
129129
```ts
130+
// Basic swap
130131
const { calldata, value } = await uniDevKit.buildSwapCallData({
131-
tokenIn,
132-
tokenOut,
133-
amountIn: "1000000000000000000",
134-
recipient,
135-
slippageBips: 50
132+
tokenIn: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
133+
amountIn: parseUnits("100", 6), // 100 USDC
134+
pool: pool,
135+
slippageTolerance: 50, // 0.5%
136+
recipient: "0x..."
137+
});
138+
139+
// Swap with permit2
140+
const permitData = await uniDevKit.preparePermit2Data({
141+
token: tokenIn,
142+
spender: uniDevKit.getContractAddress('universalRouter'),
143+
owner: userAddress
144+
});
145+
146+
const signature = await signer._signTypedData(permitData.toSign);
147+
const permitWithSignature = permitData.buildPermit2DataWithSignature(signature);
148+
149+
const { calldata: calldataWithPermit, value: valueWithPermit } = await uniDevKit.buildSwapCallData({
150+
tokenIn: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
151+
amountIn: parseUnits("100", 6),
152+
pool: pool,
153+
slippageTolerance: 50,
154+
recipient: "0x...",
155+
permit2Signature: permitWithSignature
156+
});
157+
158+
const tx = await sendTransaction({
159+
to: uniDevKit.getContractAddress('universalRouter'),
160+
data: calldata,
161+
value
136162
});
137163
```
138164

@@ -208,4 +234,4 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
208234
- Releases are automated with [semantic-release](https://semantic-release.gitbook.io/semantic-release/).
209235

210236
## License
211-
MIT
237+
MIT

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "uniswap-dev-kit",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "A modern TypeScript library for integrating Uniswap into your dapp.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/utils/buildSwapCallData.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,32 @@ const buildPermit2StructInput = (permit: PermitSingle, signature: Hex) => {
3636
*
3737
* @example
3838
* ```typescript
39+
* // Basic swap
3940
* const swapParams = {
4041
* tokenIn: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
4142
* amountIn: parseUnits("100", 6), // 100 USDC
4243
* pool: pool,
4344
* slippageTolerance: 50, // 0.5%
4445
* };
4546
*
46-
* const calldata = await buildSwapCallData(swapParams);
47+
* const calldata = await buildSwapCallData(swapParams, instance);
48+
*
49+
* // Swap with permit2
50+
* const permitData = await preparePermit2Data({
51+
* token: tokenIn,
52+
* spender: universalRouterAddress,
53+
* owner: userAddress
54+
* }, instance);
55+
*
56+
* const signature = await signer._signTypedData(permitData.toSign);
57+
* const permitWithSignature = permitData.buildPermit2DataWithSignature(signature);
58+
*
59+
* const swapParamsWithPermit = {
60+
* ...swapParams,
61+
* permit2Signature: permitWithSignature
62+
* };
63+
*
64+
* const calldataWithPermit = await buildSwapCallData(swapParamsWithPermit, instance);
4765
*
4866
* // Send transaction
4967
* const tx = await sendTransaction({

0 commit comments

Comments
 (0)