@cowprotocol/sdk-bridging 0.1.0-monorepo.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -0
- package/dist/index.d.mts +634 -0
- package/dist/index.d.ts +634 -0
- package/dist/index.js +2946 -0
- package/dist/index.mjs +2924 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width="400" src="https://github.com/cowprotocol/cow-sdk/raw/main/docs/images/CoW.png" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# SDK Bridging
|
|
6
|
+
|
|
7
|
+
This package provides bridging functionality for the CoW Protocol SDK, enabling cross-chain token transfers and interactions. It integrates with various bridge providers to facilitate seamless asset movement across supported blockchain networks.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @cowprotocol/sdk-bridging
|
|
13
|
+
or
|
|
14
|
+
pnpm add @cowprotocol/sdk-bridging
|
|
15
|
+
or
|
|
16
|
+
yarn add @cowprotocol/sdk-bridging
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Individual package usage
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import {
|
|
25
|
+
SupportedChainId,
|
|
26
|
+
BridgingSdk,
|
|
27
|
+
QuoteBridgeRequest,
|
|
28
|
+
OrderKind,
|
|
29
|
+
assertIsBridgeQuoteAndPost,
|
|
30
|
+
} from '@cowprotocol/sdk-bridging'
|
|
31
|
+
import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
|
|
32
|
+
import { JsonRpcProvider, Wallet } from 'ethers'
|
|
33
|
+
|
|
34
|
+
// Configure the adapter
|
|
35
|
+
const provider = new JsonRpcProvider('YOUR_RPC_URL')
|
|
36
|
+
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
|
|
37
|
+
const adapter = new EthersV6Adapter({ provider, signer: wallet })
|
|
38
|
+
|
|
39
|
+
// Initialize bridging SDK
|
|
40
|
+
const bridging = new BridgingSdk(adapter, options)
|
|
41
|
+
|
|
42
|
+
const parameters: QuoteBridgeRequest = {
|
|
43
|
+
// Cross-chain orders are always SELL orders (BUY not supported yet)
|
|
44
|
+
kind: OrderKind.SELL,
|
|
45
|
+
|
|
46
|
+
// Sell token (and source chain)
|
|
47
|
+
sellTokenChainId: SupportedChainId.ARBITRUM_ONE,
|
|
48
|
+
sellTokenAddress: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
|
|
49
|
+
sellTokenDecimals: 18,
|
|
50
|
+
|
|
51
|
+
// Buy token (and target chain)
|
|
52
|
+
buyTokenChainId: SupportedChainId.BASE,
|
|
53
|
+
buyTokenAddress: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
|
|
54
|
+
buyTokenDecimals: 18,
|
|
55
|
+
|
|
56
|
+
// Amount to sell
|
|
57
|
+
amount: '120000000000000000',
|
|
58
|
+
|
|
59
|
+
signer: adapter.signer,
|
|
60
|
+
|
|
61
|
+
// Optional parameters
|
|
62
|
+
appCode: 'YOUR_APP_CODE',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Get a quote (and the post callback) for a cross-chain swap
|
|
66
|
+
const quoteResult = await sdk.getQuote(parameters)
|
|
67
|
+
// Assert that the quote result is of type BridgeQuoteAndPost
|
|
68
|
+
// (type for cross-chain quotes, as opposed to QuoteAndPost for single-chain quotes).
|
|
69
|
+
// The assertion makes typescript happy.
|
|
70
|
+
assertIsBridgeQuoteAndPost(quoteResult)
|
|
71
|
+
const { swap, bridge, postSwapOrderFromQuote } = quoteResult
|
|
72
|
+
|
|
73
|
+
// Display all data related to the swap (costs, amounts, appData including the bridging hook, etc.) 🐮
|
|
74
|
+
console.log('Swap info', swap)
|
|
75
|
+
|
|
76
|
+
// Display all data related to the bridge (costs, amounts, provider info, hook, and the bridging quote) ✉️
|
|
77
|
+
console.log('Bridge info', bridge)
|
|
78
|
+
|
|
79
|
+
// Get the buy amount after slippage in the target chain
|
|
80
|
+
const { buyAmount } = bridge.amountsAndCosts.afterSlippage
|
|
81
|
+
|
|
82
|
+
if (confirm(`You will get at least: ${buyAmount}, ok?`)) {
|
|
83
|
+
const orderId = await postSwapOrderFromQuote()
|
|
84
|
+
console.log('Order created, id: ', orderId)
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Usage with Umbrella SDK
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import {
|
|
92
|
+
CowSdk,
|
|
93
|
+
SupportedChainId,
|
|
94
|
+
QuoteBridgeRequest,
|
|
95
|
+
OrderKind,
|
|
96
|
+
assertIsBridgeQuoteAndPost,
|
|
97
|
+
} from '@cowprotocol/cow-sdk'
|
|
98
|
+
import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
|
|
99
|
+
import { JsonRpcProvider, Wallet } from 'ethers'
|
|
100
|
+
|
|
101
|
+
// Configure the adapter
|
|
102
|
+
const provider = new JsonRpcProvider('YOUR_RPC_URL')
|
|
103
|
+
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
|
|
104
|
+
const adapter = new EthersV6Adapter({ provider, signer: wallet })
|
|
105
|
+
|
|
106
|
+
// Initialize the unified SDK
|
|
107
|
+
const sdk = new CowSdk({
|
|
108
|
+
chainId: SupportedChainId.ARBITRUM_ONE, // Source chain
|
|
109
|
+
adapter,
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const parameters: QuoteBridgeRequest = {
|
|
113
|
+
// Cross-chain orders are always SELL orders (BUY not supported yet)
|
|
114
|
+
kind: OrderKind.SELL,
|
|
115
|
+
|
|
116
|
+
// Sell token (and source chain)
|
|
117
|
+
sellTokenChainId: SupportedChainId.ARBITRUM_ONE,
|
|
118
|
+
sellTokenAddress: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
|
|
119
|
+
sellTokenDecimals: 18,
|
|
120
|
+
|
|
121
|
+
// Buy token (and target chain)
|
|
122
|
+
buyTokenChainId: SupportedChainId.BASE,
|
|
123
|
+
buyTokenAddress: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
|
|
124
|
+
buyTokenDecimals: 18,
|
|
125
|
+
|
|
126
|
+
// Amount to sell
|
|
127
|
+
amount: '120000000000000000',
|
|
128
|
+
|
|
129
|
+
signer: adapter.signer,
|
|
130
|
+
|
|
131
|
+
// Optional parameters
|
|
132
|
+
appCode: 'YOUR_APP_CODE',
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Access bridging through the umbrella SDK
|
|
136
|
+
const quoteResult = await sdk.bridging.getQuote(parameters)
|
|
137
|
+
assertIsBridgeQuoteAndPost(quoteResult)
|
|
138
|
+
const { swap, bridge, postSwapOrderFromQuote } = quoteResult
|
|
139
|
+
|
|
140
|
+
// Display all data related to the swap and bridge
|
|
141
|
+
console.log('Swap info', swap)
|
|
142
|
+
console.log('Bridge info', bridge)
|
|
143
|
+
|
|
144
|
+
// Get the buy amount after slippage in the target chain
|
|
145
|
+
const { buyAmount } = bridge.amountsAndCosts.afterSlippage
|
|
146
|
+
|
|
147
|
+
if (confirm(`You will get at least: ${buyAmount}, ok?`)) {
|
|
148
|
+
const orderId = await postSwapOrderFromQuote()
|
|
149
|
+
console.log('Order created, id: ', orderId)
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Supported Bridge Providers
|
|
154
|
+
|
|
155
|
+
- Additional bridge providers are being integrated
|
|
156
|
+
- More details will be available as development progresses
|