-
Notifications
You must be signed in to change notification settings - Fork 106
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/Delta support #183
Merged
Merged
Feat/Delta support #183
Changes from 170 commits
Commits
Show all changes
186 commits
Select commit
Hold shift + click to select a range
cad44c9
update build dependencies
Velenir 974a802
update tsconfig
Velenir 14294e3
actions/remove Node18
Velenir 93b7826
fix types
Velenir 2109de9
extra gitignore
Velenir da9d495
update typedoc deps
Velenir eac78e6
update snapshots
Velenir feb6631
abstract away providers/findPrimaryType
Velenir 8a36c72
add TransactionParams.maxFeeGas params
Velenir 35f45dd
providers/viem
Velenir ab08a0e
export from providers/viem
Velenir 5930b5c
DEFAULT_VERSION better type
Velenir ee465f9
add wagmi & viem deps
Velenir 2120841
SimpleSDK/viem for contractCaller
Velenir dc7b9a8
examples/viem
Velenir b9216f4
cleanup
Velenir ed18b71
examples/wagmi
Velenir c785a04
fix dependencies
Velenir b463812
Merge branch 'feat/build_upgrade' into feat/viem_support
Velenir 12644b9
tests/fix types
Velenir 1740831
examples/fix types
Velenir 582eefc
tests/fix types
Velenir 9e99ee1
viem/fix account usage
Velenir dfa0e2b
examples/viem/fix account usage
Velenir 0e8a916
types/TxHash=Hex
Velenir 1d6ed0f
add hardhat
Velenir 33fc15e
legacy/fix types
Velenir bd73372
ignore cache files
Velenir 071dc3d
some tests
Velenir c57d043
tsconfig/allow BigInt short notation
Velenir dc8c3c2
providers/viem/reuse account
Velenir a0e80e9
viem/fix tests
Velenir c3b72ac
tests/viem/remove extra
Velenir 84382f8
tests/viem/Order signing
Velenir d8f82fc
rename stuff
Velenir 7f22798
cleanup
Velenir 7327226
reenable tests
Velenir b068165
tests/viem/const acc
Velenir ab1ded2
tests/viem/update snapshots
Velenir ff055fb
reexport txParamsToViemTxParams
Velenir 9d1fdb3
tests/viem/update snapshots
Velenir c9de532
more comments
Velenir c94a386
cleanup
Velenir 536efb9
remove extra deps
Velenir 4f3df54
moved bignumber.js to devDeps
Velenir 8399183
cleanup
Velenir 45f72d4
update tests jpeg
Velenir fc3976f
update README
Velenir 5c35317
update snapshots
Velenir b637c47
FetcherError/fix types
Velenir b368e93
viem test/market swap
Velenir 4719ce0
fix deps
Velenir 64f3216
update deps
Velenir e56cf76
update snapshots
Velenir 085823b
remove dummy test
Velenir 332d98b
change default version
Velenir 5d392d7
Merge branch 'master' into feat/build_upgrade
Velenir 24e868c
Merge branch 'feat/build_upgrade' into feat/viem_support
Velenir e11a89c
update some deps
Velenir 57a9f24
replace ganache with hardhat
Velenir ed68254
remove ganache
Velenir 15887c1
fix chainId in tests mismatch
Velenir cc2d0a3
try with tevm
Velenir 27adcce
tevm test
Velenir 0d59580
add hardhat-switch-network plugin
Velenir 641005c
simplify hardhat helpers
Velenir 292c084
make tests work with hardhat
Velenir 3201dc4
fix method name
Velenir dfe8d85
disable web3 tests that break with hardhat
Velenir 1f3543d
fix NFT tests
Velenir 24b2f6b
remove tevm
Velenir 0ac1d30
hardhat config/explicit gasPrice
Velenir 8a5d211
NFT tests/adjust amounts
Velenir f29ad59
cleanup
Velenir 04ef27f
remove temp tests
Velenir 6360f0f
update some deps
Velenir 167f353
NFT tests/workaround some errors
Velenir 82c6c7f
update ethers dep
Velenir 0383da6
update web3 dep(slightly)
Velenir 929b018
update deps
Velenir 570622f
override some deps
Velenir 2f807f7
update some deps
Velenir 2ea62c9
hadrhat config/smaller default baseFee
Velenir edd167b
NFT tests/workaround edge case
Velenir b414a35
update web3 dep
Velenir bd3afc4
update Web3 types
Velenir f4fdaf5
update web3/constructContractCaller
Velenir 0c72307
legacy/update types
Velenir 98b9e7c
hardhat config/fixed accounts
Velenir dc20224
LOrder tests/reenable sign with web3
Velenir e66c42d
NFT Order tests/reenable sign with web3
Velenir dda380c
getBalance tests workaround
Velenir 73e5fab
cleanup
Velenir 23812f6
update some deps
Velenir 55d43a3
update snapshots
Velenir eab3190
update perrDeps
Velenir 1410e67
update required Node v
Velenir 4fb50ba
NFT tests/account for dust
Velenir 3978301
hadrhat config/lower initialBaseFeePerGas
Velenir c6007a0
install ethersV6 as alias
Velenir 850c61a
providers/ethersV6
Velenir 2e1a118
distinct ethersV5 exports
Velenir a522f47
legacy/support ethersV6
Velenir d402eb9
simple SDK/support ethersV6
Velenir b567f64
simpleSDK.tests/add ethersV6
Velenir 0bcb538
partialSDK.tests/add ethersV6
Velenir 648a5f6
LOrders.tests/add ethersV6
Velenir e00a65a
NFT_Orders.tests/add ethersV6
Velenir 9639ea7
update snapshots
Velenir e94a5e1
examples/ add ethersV6
Velenir 92e57a4
perrDeps/update ethers versions
Velenir 5a89ef9
update snapshots
Velenir 0df1bf4
cleanup
Velenir f09cce5
delta/approve
Velenir 9885605
delta/getContract
Velenir b92dccd
delta/getOrders
Velenir 5c3bf86
delta/some types
Velenir 43ef400
delta/getPrice
Velenir 0721865
delta/getPartnerFee
Velenir 5b357fe
delta/sanitizeOrderData
Velenir c92f9b9
delta/composePermit
Velenir 3fbd1f7
delta/buildOrderData
Velenir 95db6c3
delta/buildData
Velenir 05946bc
delta/signOrder
Velenir c405936
extend AdaptersContractsResult
Velenir 4c24256
delta/postOrder
Velenir 4e990e6
delta/submitOrder & allHandlers
Velenir 2dc0233
delta/buildOrder/explicit BuildDeltaOrderDataParams
Velenir dbf3804
add PartnerFeeResponse.takeSurplus
Velenir e26d523
reexport Delta methods & types
Velenir 5b32abd
BuildDeltaOrderDataParams.partner?
Velenir 87ef000
DeltaPriceParams.*decimals: required
Velenir a8f8c29
examples/delta
Velenir b7c77a0
fullSDK/delta methods
Velenir cd268a8
simpleSDK/delta methods
Velenir 797c847
producePartnerAndFee |= (takeSuplus << 8)
Velenir ce9a82a
examples/delta/manualDeltaFlow
Velenir 61885f2
cleanup
Velenir 48e619e
move ethers types to provider/ethers
Velenir 1098429
move web3 types to provider/web3
Velenir 7f12f34
untie FetchError type from AxiosError
Velenir e20b6ad
cleanup
Velenir e887e6c
reexport DeltaPriceParams
Velenir 9953b66
ethers -> ethersV5, ethersV6 -> ethers to fix types when used as lib
Velenir 387b427
deriveCompactSignature
Velenir 2633abc
signDeltaOrder/deriveCompactSignature
Velenir 1eee8ae
move ethers types to provider/ethers
Velenir 4e9e56a
move web3 types to provider/web3
Velenir e10b1bc
untie FetchError type from AxiosError
Velenir c165dd4
ethers -> ethersV5, ethersV6 -> ethers to fix types when used as lib
Velenir f550265
cleanup
Velenir 6369f4a
Merge branch 'feat/etherV6_support' into feat/delta
Velenir 3455fe1
fetch/remove unnecessary headers
Velenir cbb1e68
delta/examples/fix slippage
Velenir 432b6f4
reexport more types
Velenir f4269c3
cleanup
Velenir 6f8f565
delta/getPrices/fix query params
Velenir 5d066e7
type DeltaPrice/add fields
Velenir 9eec5ef
Partial/delta/approve/fix tx type
Velenir e1720be
ethersV6/more explicit Contract method calling
Velenir 3b03b05
delta/add tests
Velenir df4e822
delta/getPartnerFee/temp workaround for API response
Velenir 36fb501
README/update version
Velenir 1ba0be8
README/update version
Velenir 2a47009
less dependency on ethers types
Velenir 9103ded
update README
Velenir ace4561
Merge branch 'feat/etherV6_support' into feat/delta
Velenir 6535106
cleanup
Velenir 68cb246
remove default partner
Velenir b2df52c
Merge branch 'master' into feat/delta
Velenir 08b8a8d
remove temp tests
Velenir eb39af5
ParaswapDeltaAuction.orderHash: string | null
Velenir 9671e2a
cleanup
Velenir 8828039
fix typos
Velenir 55780f3
cleanup
Velenir a07084d
replace deprecated method
Velenir 7a881f1
Delta/signDeltaOrder/skip compact sig when incompatible
Velenir 63668af
update Delta Order types
Velenir da9351e
update tests
Velenir 30cf0de
fix typo
Velenir 68467fe
Delta/update types
Velenir b8abf85
tests/Delta/update snapshots
Velenir 59f66f7
Merge branch 'master' into feat/delta
Velenir 2a0f9ae
Delta/annotate some types
Velenir e69c88c
Delta/getDEltaOrders/pagination options
Velenir d571daf
Feat/Quote support (#185)
Velenir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import axios from 'axios'; | ||
import { ethers, Wallet } from 'ethersV5'; | ||
import { | ||
constructPartialSDK, | ||
constructEthersContractCaller, | ||
constructAxiosFetcher, | ||
constructAllDeltaOrdersHandlers, | ||
} from '..'; | ||
|
||
const fetcher = constructAxiosFetcher(axios); | ||
|
||
const provider = ethers.getDefaultProvider(1); | ||
const signer = Wallet.createRandom().connect(provider); | ||
const account = signer.address; | ||
const contractCaller = constructEthersContractCaller({ | ||
ethersProviderOrSigner: provider, | ||
EthersContract: ethers.Contract, | ||
}); | ||
|
||
// type AdaptersFunctions & ApproveTokenFunctions<ethers.ContractTransaction> | ||
const deltaSDK = constructPartialSDK( | ||
{ | ||
chainId: 1, | ||
fetcher, | ||
contractCaller, | ||
}, | ||
constructAllDeltaOrdersHandlers | ||
); | ||
|
||
const DAI_TOKEN = '0x6b175474e89094c44da98b954eedeac495271d0f'; | ||
const PSP_TOKEN = '0xcafe001067cdef266afb7eb5a286dcfd277f3de5'; | ||
|
||
async function simpleDeltaFlow() { | ||
const amount = '1000000000000'; // wei | ||
|
||
const deltaPrice = await deltaSDK.getDeltaPrice({ | ||
srcToken: DAI_TOKEN, | ||
destToken: PSP_TOKEN, | ||
amount: '1000000000000', | ||
userAddress: account, | ||
srcDecimals: 18, | ||
destDecimals: 18, | ||
// partner: "..." // if available | ||
}); | ||
|
||
const DeltaContract = await deltaSDK.getDeltaContract(); | ||
|
||
// or sign a Permit1 or Permit2 TransferFrom for DeltaContract | ||
await deltaSDK.approveTokenForDelta(amount, DAI_TOKEN); | ||
|
||
const slippagePercent = 0.5; | ||
const destAmountAfterSlippage = BigInt( | ||
// get rid of exponential notation | ||
|
||
+(+deltaPrice.destAmount * (1 - slippagePercent / 100)).toFixed(0) | ||
// get rid of decimals | ||
).toString(10); | ||
|
||
const deltaAuction = await deltaSDK.submitDeltaOrder({ | ||
deltaPrice, | ||
owner: account, | ||
// beneficiary: anotherAccount, // if need to send destToken to another account | ||
// permit: "0x1234...", // if signed a Permit1 or Permit2 TransferFrom for DeltaContract | ||
srcToken: DAI_TOKEN, | ||
destToken: PSP_TOKEN, | ||
srcAmount: amount, | ||
destAmount: destAmountAfterSlippage, // minimum acceptable destAmount | ||
}); | ||
|
||
// poll if necessary | ||
const auction = await deltaSDK.getDeltaOrderById(deltaAuction.id); | ||
if (auction?.status === 'EXECUTED') { | ||
console.log('Auction was executed'); | ||
} | ||
} | ||
async function manualDeltaFlow() { | ||
const amount = '1000000000000'; // wei | ||
|
||
const deltaPrice = await deltaSDK.getDeltaPrice({ | ||
srcToken: DAI_TOKEN, | ||
destToken: PSP_TOKEN, | ||
amount: '1000000000000', | ||
userAddress: account, | ||
srcDecimals: 18, | ||
destDecimals: 18, | ||
// partner: "..." // if available | ||
}); | ||
|
||
const DeltaContract = await deltaSDK.getDeltaContract(); | ||
|
||
// or sign a Permit1 or Permit2 TransferFrom for DeltaContract | ||
await deltaSDK.approveTokenForDelta(amount, DAI_TOKEN); | ||
|
||
const slippagePercent = 0.5; | ||
const destAmountAfterSlippage = ( | ||
+deltaPrice.destAmount * | ||
(1 - slippagePercent / 100) | ||
).toString(10); | ||
|
||
const signableOrderData = await deltaSDK.buildDeltaOrder({ | ||
deltaPrice, | ||
owner: account, | ||
// beneficiary: anotherAccount, // if need to send destToken to another account | ||
// permit: "0x1234...", // if signed a Permit1 or Permit2 TransferFrom for DeltaContract | ||
srcToken: DAI_TOKEN, | ||
destToken: PSP_TOKEN, | ||
srcAmount: amount, | ||
destAmount: destAmountAfterSlippage, // minimum acceptable destAmount | ||
}); | ||
|
||
const signature = await deltaSDK.signDeltaOrder(signableOrderData); | ||
|
||
const deltaAuction = await deltaSDK.postDeltaOrder({ | ||
// partner: "..." // if available | ||
order: signableOrderData.data, | ||
signature, | ||
}); | ||
|
||
// poll if necessary | ||
const auction = await deltaSDK.getDeltaOrderById(deltaAuction.id); | ||
if (auction?.status === 'EXECUTED') { | ||
console.log('Auction was executed'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -131,6 +131,48 @@ import type { | |||||
ParaSwapVersionUnion as ParaSwapVersion, | ||||||
} from './types'; | ||||||
|
||||||
import type { | ||||||
DeltaAuctionOrder, | ||||||
ParaswapDeltaAuction, | ||||||
} from './methods/delta/helpers/types'; | ||||||
import { | ||||||
BuildDeltaOrderDataParams, | ||||||
BuildDeltaOrderFunctions, | ||||||
constructBuildDeltaOrder, | ||||||
SignableDeltaOrderData, | ||||||
} from './methods/delta/buildDeltaOrder'; | ||||||
import { | ||||||
constructPostDeltaOrder, | ||||||
PostDeltaOrderFunctions, | ||||||
PostDeltaOrderParams, | ||||||
} from './methods/delta/postDeltaOrder'; | ||||||
import { | ||||||
constructSignDeltaOrder, | ||||||
SignDeltaOrderFunctions, | ||||||
} from './methods/delta/signDeltaOrder'; | ||||||
import { | ||||||
GetDeltaContractFunctions, | ||||||
constructGetDeltaContract, | ||||||
} from './methods/delta/getDeltaContract'; | ||||||
import { | ||||||
constructGetDeltaPrice, | ||||||
GetDeltaPriceFunctions, | ||||||
DeltaPrice, | ||||||
DeltaPriceParams, | ||||||
} from './methods/delta/getDeltaPrice'; | ||||||
import { | ||||||
constructGetDeltaOrders, | ||||||
GetDeltaOrdersFunctions, | ||||||
} from './methods/delta/getDeltaOrders'; | ||||||
import { | ||||||
ApproveTokenForDeltaFunctions, | ||||||
constructApproveTokenForDelta, | ||||||
} from './methods/delta/approveForDelta'; | ||||||
import { | ||||||
constructGetPartnerFee, | ||||||
GetPartnerFeeFunctions, | ||||||
} from './methods/delta/getPartnerFee'; | ||||||
|
||||||
export { constructSwapSDK, SwapSDKMethods } from './methods/swap'; | ||||||
|
||||||
export { | ||||||
|
@@ -139,6 +181,12 @@ export { | |||||
LimitOrderHandlers, | ||||||
} from './methods/limitOrders'; | ||||||
|
||||||
export { | ||||||
constructAllDeltaOrdersHandlers, | ||||||
constructSubmitDeltaOrder, | ||||||
DeltaOrderHandlers, | ||||||
} from './methods/delta'; | ||||||
|
||||||
export type { | ||||||
TransactionParams, | ||||||
BuildOptions, | ||||||
|
@@ -198,7 +246,16 @@ export { | |||||
constructApproveTokenForNFTOrder, | ||||||
constructGetNFTOrdersContract, | ||||||
constructBuildNFTOrderTx, | ||||||
// Delta methods | ||||||
constructBuildDeltaOrder, | ||||||
constructPostDeltaOrder, | ||||||
constructSignDeltaOrder, | ||||||
constructGetDeltaContract, | ||||||
constructGetDeltaPrice, | ||||||
constructGetDeltaOrders, | ||||||
constructApproveTokenForDelta, | ||||||
// different helpers | ||||||
constructGetPartnerFee, | ||||||
constructEthersContractCaller, // same as constructEthersV5ContractCaller for backwards compatibility | ||||||
constructEthersV5ContractCaller, | ||||||
constructEthersV6ContractCaller, | ||||||
|
@@ -256,11 +313,27 @@ export type { | |||||
BuildNFTOrderInput, | ||||||
BuildNFTOrderDataInput, | ||||||
NFTOrdersUserParams, | ||||||
//types for Delta methos | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
DeltaPrice, | ||||||
DeltaPriceParams, | ||||||
DeltaAuctionOrder, | ||||||
ParaswapDeltaAuction, | ||||||
BuildDeltaOrderDataParams, | ||||||
BuildDeltaOrderFunctions, | ||||||
SignableDeltaOrderData, | ||||||
PostDeltaOrderFunctions, | ||||||
PostDeltaOrderParams, | ||||||
SignDeltaOrderFunctions, | ||||||
GetDeltaContractFunctions, | ||||||
GetDeltaPriceFunctions, | ||||||
GetDeltaOrdersFunctions, | ||||||
ApproveTokenForDeltaFunctions, | ||||||
//common | ||||||
ConstructFetchInput, | ||||||
ContractCallerFunctions, | ||||||
ConstructProviderFetchInput, | ||||||
// other types | ||||||
GetPartnerFeeFunctions, | ||||||
Token, | ||||||
Address, | ||||||
AddressOrSymbol, | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { ConstructProviderFetchInput } from '../../types'; | ||
import { ApproveToken, approveTokenMethodFactory } from '../../helpers/approve'; | ||
import { constructGetDeltaContract } from './getDeltaContract'; | ||
|
||
export type ApproveTokenForDeltaFunctions<T> = { | ||
/** @description approving ParaswapDelta as spender for Token */ | ||
approveTokenForDelta: ApproveToken<T>; | ||
}; | ||
|
||
// returns whatever `contractCaller` returns | ||
// to allow for better versatility | ||
export const constructApproveTokenForDelta = <T>( | ||
options: ConstructProviderFetchInput<T, 'transactCall'> | ||
): ApproveTokenForDeltaFunctions<T> => { | ||
// getAugustusRFQ is cached internally for the same instance of SDK | ||
// so should persist across same apiUrl & network | ||
const { getDeltaContract } = constructGetDeltaContract(options); | ||
|
||
const getParaswapDelta = async () => { | ||
const deltaContract = await getDeltaContract(); | ||
if (!deltaContract) { | ||
throw new Error(`Delta is not available on chain ${options.chainId}`); | ||
} | ||
return deltaContract; | ||
}; | ||
|
||
const approveTokenForDelta: ApproveToken<T> = approveTokenMethodFactory<T>( | ||
options.contractCaller, | ||
getParaswapDelta | ||
); | ||
|
||
return { | ||
approveTokenForDelta, | ||
}; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that I don't have linter errors here without disabling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strangely, I also don't have errors anymore 🤷