Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sdk extension for people to swap #213

Merged
merged 73 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
6788008
feat: SDK extension for people to swap
shoom3301 Jun 26, 2024
e8927e2
feat: SDK extension for people to trade
shoom3301 Jun 26, 2024
59f550b
refactor: move files to trading dir
shoom3301 Jun 27, 2024
ee092bb
feat: js example for trade-sdk
shoom3301 Jun 27, 2024
775e687
chore: trade sdk examples
shoom3301 Jun 28, 2024
bbece96
docs: trading SDK docs
shoom3301 Jul 5, 2024
f27a94d
chore: encapsulate networkCostsAmount
shoom3301 Jul 5, 2024
d98230a
Merge branch 'main' of https://github.com/cowprotocol/cow-sdk into fe…
shoom3301 Jul 5, 2024
f82841d
chore: fix build
shoom3301 Jul 5, 2024
5639517
chore: fix build
shoom3301 Jul 5, 2024
92c7d14
Merge branch 'main' of https://github.com/cowprotocol/cow-sdk into fe…
shoom3301 Sep 2, 2024
6896b20
Merge branch 'main' of https://github.com/cowprotocol/cow-sdk into fe…
shoom3301 Nov 5, 2024
94b21ff
chore: make networkCostsAmount optional
shoom3301 Nov 5, 2024
bf87d83
feat: calculate unique OrderId util
shoom3301 Nov 6, 2024
9c23fae
feat: support on-chain trades
shoom3301 Nov 7, 2024
6fcff58
chore: reduce getOrderToSign parameters
shoom3301 Nov 7, 2024
490e7d4
Merge branch 'main' of https://github.com/cowprotocol/cow-sdk into fe…
shoom3301 Nov 7, 2024
4a1f35e
feat: support on-chain orders
shoom3301 Nov 7, 2024
240ebfb
test: app data utils
shoom3301 Nov 7, 2024
a8d1ec9
test: test calculateUniqueOrderId
shoom3301 Nov 7, 2024
59fd04b
test: test getOrderToSign
shoom3301 Nov 7, 2024
6351ae7
test: test getQuote
shoom3301 Nov 8, 2024
56692ab
test: test postCoWProtocolTrade
shoom3301 Nov 8, 2024
9d828bf
test: test postLimitOrder
shoom3301 Nov 8, 2024
f106189
test: test postOnChainTrade
shoom3301 Nov 8, 2024
99a1cad
docs: docs for postOnChainTrade
shoom3301 Nov 8, 2024
5698598
Merge branch 'main' of https://github.com/cowprotocol/cow-sdk into fe…
shoom3301 Nov 8, 2024
03d212e
chore: up docs
shoom3301 Nov 8, 2024
867b05e
fix: update eth-flow addresses
shoom3301 Nov 8, 2024
62ee519
chore: fix tests
shoom3301 Nov 8, 2024
4f788ed
chore: export helpers
shoom3301 Nov 8, 2024
953f848
chore: rc version
shoom3301 Nov 12, 2024
2338f92
chore: fix readme
shoom3301 Nov 18, 2024
6b8a7a2
feat: avoid using signer in getQuote
shoom3301 Nov 19, 2024
a054c43
chore: rc
shoom3301 Nov 19, 2024
b878eb1
chore: move QuoteResults to types
shoom3301 Nov 19, 2024
e99875c
refactor: make QuoteResults serializable
shoom3301 Nov 19, 2024
18ad494
feat: add json schemas for trading entities
shoom3301 Nov 19, 2024
16d7bd2
chore: rc
shoom3301 Nov 20, 2024
f5af9bd
chore: up node v
shoom3301 Nov 20, 2024
899fb0f
chore: remove schema gen call
shoom3301 Nov 20, 2024
d4a0a1b
chore: up app-data version
shoom3301 Nov 22, 2024
45d5e96
chore: bump version
shoom3301 Nov 22, 2024
3191677
feat: add order typed data to quote results
shoom3301 Nov 22, 2024
228f3d7
fix: fix order signing
shoom3301 Nov 22, 2024
e1ac3b9
fix: override sellToken with wrapped for eth-flow
shoom3301 Nov 26, 2024
dccbc42
feat(trading): function to generate eth-flow transaction
shoom3301 Nov 26, 2024
9bc094d
chore: export swapParamsToLimitOrderParams
shoom3301 Nov 26, 2024
3e55086
fix: use hex numbers in transaction
shoom3301 Nov 26, 2024
718b212
fix(trading): fix order amounts calculation
shoom3301 Nov 26, 2024
8e83b08
chore: bump rc
shoom3301 Nov 26, 2024
54e279b
chore: fix tests
shoom3301 Nov 26, 2024
365a604
chore: add mapQuoteAmountsAndCosts util
shoom3301 Nov 26, 2024
0843dca
chore: fix types
shoom3301 Nov 26, 2024
bb96203
chore: do not cache ethflow contract
shoom3301 Nov 27, 2024
6b718f6
test: test getEthFlowTransaction
shoom3301 Nov 27, 2024
6adfc55
feat(trading): add getPreSignTransaction function
shoom3301 Nov 27, 2024
1cf851f
chore: add more description to trading types
shoom3301 Nov 27, 2024
1ff1f2f
chore: fix test
shoom3301 Nov 27, 2024
b8fccff
chore: update trading sdk readme
shoom3301 Nov 28, 2024
2500eef
chore: up rc
shoom3301 Nov 28, 2024
1e81003
Merge branch 'main' of https://github.com/cowprotocol/cow-sdk into fe…
shoom3301 Dec 5, 2024
b26cf2d
chore: fix base contract addresses
shoom3301 Dec 5, 2024
26d822b
fix: make quoteId optional for limit orders
shoom3301 Dec 5, 2024
6739150
refactor: rename postOnChainTrade -> postSellNativeCurrencyTrade
shoom3301 Dec 5, 2024
bb31db3
docs: optional params
shoom3301 Dec 5, 2024
da3749c
chore: fix tests
shoom3301 Dec 5, 2024
61aad12
fix: add additional params for eth-flow quote req
shoom3301 Dec 5, 2024
cc7b2b4
feat: add getPreSignTransaction to TradingSdk
shoom3301 Dec 5, 2024
b21a9f8
docs: get quest for smart-contract wallet
shoom3301 Dec 5, 2024
6fc34fd
chore: rename postSellNativeCurrencyOrder
shoom3301 Dec 5, 2024
31b1498
docs: create an order with smart-contract wallet
shoom3301 Dec 11, 2024
eec09d4
chore: fix tests
shoom3301 Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
]
},

"ignorePatterns": ["dist", "node_modules", "src/subgraph/graphql.ts", "examples"]
"ignorePatterns": ["dist", "node_modules", "src/subgraph/graphql.ts", "examples", "schemas"]
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
types: [published]

env:
NODE_VERSION: lts/gallium
NODE_VERSION: lts/hydrogen

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [published]

env:
NODE_VERSION: lts/gallium
NODE_VERSION: lts/hydrogen

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Unit tests & Coverage
on: [push, pull_request]

env:
NODE_VERSION: lts/gallium
NODE_VERSION: lts/hydrogen
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

jobs:
Expand Down
152 changes: 152 additions & 0 deletions abi/EthFlow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
[
{
"inputs": [
{
"components": [
{
"internalType": "contract IERC20",
"name": "buyToken",
"type": "address"
},
{
"internalType": "address",
"name": "receiver",
"type": "address"
},
{
"internalType": "uint256",
"name": "sellAmount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "buyAmount",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "appData",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "feeAmount",
"type": "uint256"
},
{
"internalType": "uint32",
"name": "validTo",
"type": "uint32"
},
{
"internalType": "bool",
"name": "partiallyFillable",
"type": "bool"
},
{
"internalType": "int64",
"name": "quoteId",
"type": "int64"
}
],
"internalType": "struct EthFlowOrder.Data",
"name": "order",
"type": "tuple"
}
],
"name": "createOrder",
"outputs": [
{
"internalType": "bytes32",
"name": "orderHash",
"type": "bytes32"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "contract IERC20",
"name": "buyToken",
"type": "address"
},
{
"internalType": "address",
"name": "receiver",
"type": "address"
},
{
"internalType": "uint256",
"name": "sellAmount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "buyAmount",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "appData",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "feeAmount",
"type": "uint256"
},
{
"internalType": "uint32",
"name": "validTo",
"type": "uint32"
},
{
"internalType": "bool",
"name": "partiallyFillable",
"type": "bool"
},
{
"internalType": "int64",
"name": "quoteId",
"type": "int64"
}
],
"internalType": "struct EthFlowOrder.Data",
"name": "order",
"type": "tuple"
}
],
"name": "invalidateOrder",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"name": "orders",
"outputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "uint32",
"name": "validTo",
"type": "uint32"
}
],
"stateMutability": "view",
"type": "function"
}
]
89 changes: 89 additions & 0 deletions abi/GPv2Settlement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": false,
"internalType": "contract IERC20",
"name": "sellToken",
"type": "address"
},
{
"indexed": false,
"internalType": "contract IERC20",
"name": "buyToken",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "sellAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "buyAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "feeAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "bytes",
"name": "orderUid",
"type": "bytes"
}
],
"name": "Trade",
"type": "event"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "orderUid",
"type": "bytes"
},
{
"internalType": "bool",
"name": "signed",
"type": "bool"
}
],
"name": "setPreSignature",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "orderUid",
"type": "bytes"
}
],
"name": "invalidateOrder",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "domainSeparator",
"outputs": [{ "name": "", "type": "bytes32" }],
"stateMutability": "nonpayable",
"type": "function"
}
]
2 changes: 1 addition & 1 deletion examples/cra/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
},
"include": [
"src"
]
Expand Down
73 changes: 63 additions & 10 deletions examples/nodejs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,69 @@
import { OrderBookApi, SubgraphApi, SupportedChainId } from '@cowprotocol/cow-sdk'
import { SupportedChainId, OrderKind, postSwapOrder, postLimitOrder } from '../../../src'

// See more examples in /examples/cra
const privateKey = 'xxx'

// Swap
;(async function () {
const orderBookApi = new OrderBookApi({ chainId: SupportedChainId.MAINNET })
const subgraphApi = new SubgraphApi({ chainId: SupportedChainId.MAINNET })
return

const order = await orderBookApi.getOrder(
'0xff2e2e54d178997f173266817c1e9ed6fee1a1aae4b43971c53b543cffcc2969845c6f5599fbb25dbdd1b9b013daf85c03f3c63763e4bc4a'
)
postSwapOrder({
appCode: 'cow-sdk-example',
signer: privateKey,
chainId: SupportedChainId.SEPOLIA,

kind: OrderKind.SELL,
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
sellTokenDecimals: 18,
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
buyTokenDecimals: 18,
amount: '120000000000000000',
})
})()

// Limit order
;(async function () {
return

const lastDaysVolume = await subgraphApi.getTotals()
postLimitOrder({
appCode: 'cow-sdk-example',
signer: privateKey,
chainId: SupportedChainId.SEPOLIA,

console.log('[orderBookApi] Order: ', order)
console.log('[subgraphApi] Last day volume: ', lastDaysVolume)
kind: OrderKind.BUY,
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
sellTokenDecimals: 18,
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
buyTokenDecimals: 18,
sellAmount: '120000000000000000',
buyAmount: '66600000000000000000',
networkCostsAmount: '0',
})
})()

// Swap with partner fee
;(async function () {
postSwapOrder(
{
appCode: 'cow-sdk-example',
signer: privateKey,
chainId: SupportedChainId.SEPOLIA,

kind: OrderKind.SELL,
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
sellTokenDecimals: 18,
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
buyTokenDecimals: 18,
amount: '120000000000000000',
},
{
appData: {
metadata: {
partnerFee: {
bps: 100,
recipient: '0xfb3c7eb936cAA12B5A884d612393969A557d4307',
},
},
},
}
)
})()
6 changes: 3 additions & 3 deletions examples/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"start": "webpack serve --mode=development",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@cowprotocol/cow-sdk": "^4.0.3"
},
"dependencies": {},
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^7.1.2",
"html-webpack-plugin": "^5.5.0",
"style-loader": "^4.0.0",
"ts-loader": "^9.4.2",
"webpack": "^5.76.3",
"webpack-cli": "^5.0.1",
Expand Down
Loading
Loading