Skip to content

Commit

Permalink
Merge pull request #87 from clober-dex/feat/remove-permit-function
Browse files Browse the repository at this point in the history
refactor: remove `signERC20Permit` function
  • Loading branch information
graykode authored Aug 14, 2024
2 parents 4776d75 + 6e402ed commit 80855c4
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 271 deletions.
21 changes: 3 additions & 18 deletions examples/limit-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { createWalletClient, http, parseUnits } from 'viem'
import { arbitrumSepolia } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
import * as dotenv from 'dotenv'
import {
getMarket,
getOpenOrders,
limitOrder,
signERC20Permit,
} from '@clober/v2-sdk'
import { getMarket, getOpenOrders, limitOrder } from '@clober/v2-sdk'

dotenv.config()

Expand All @@ -20,34 +15,24 @@ const main = async () => {
transport: http(),
})

const erc20PermitParam = await signERC20Permit({
chainId: arbitrumSepolia.id,
walletClient,
token: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
amount: '1.12',
})

const {
transaction,
result: { make, taken },
result: { make, take },
} = await limitOrder({
chainId: arbitrumSepolia.id,
userAddress: walletClient.account.address,
inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
outputToken: '0x0000000000000000000000000000000000000000',
amount: '1.12',
price: '8000.01',
options: {
erc20PermitParam: erc20PermitParam!,
},
})
const hash = await walletClient.sendTransaction({
...transaction,
gasPrice: parseUnits('1', 9),
})
console.log(`limit order hash: ${hash}`)
console.log(`make: `, make)
console.log(`taken: `, taken)
console.log(`take: `, take)

const market = await getMarket({
chainId: arbitrumSepolia.id,
Expand Down
16 changes: 3 additions & 13 deletions examples/market-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createWalletClient, http, parseUnits } from 'viem'
import { arbitrumSepolia } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
import * as dotenv from 'dotenv'
import { getMarket, marketOrder, signERC20Permit } from '@clober/v2-sdk'
import { getMarket, marketOrder } from '@clober/v2-sdk'

dotenv.config()

Expand All @@ -15,32 +15,22 @@ const main = async () => {
transport: http(),
})

const erc20PermitParam = await signERC20Permit({
chainId: arbitrumSepolia.id,
walletClient,
token: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
amount: '1.12',
})

const {
transaction,
result: { spent, take },
result: { spend, take },
} = await marketOrder({
chainId: arbitrumSepolia.id,
userAddress: walletClient.account.address,
inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
outputToken: '0x0000000000000000000000000000000000000000',
amountIn: '1.12',
options: {
erc20PermitParam: erc20PermitParam!,
},
})
const hash = await walletClient.sendTransaction({
...transaction,
gasPrice: parseUnits('1', 9),
})
console.log(`market order hash: ${hash}`)
console.log(`spent: `, spent)
console.log(`spend: `, spend)
console.log(`take: `, take)

const market = await getMarket({
Expand Down
19 changes: 2 additions & 17 deletions src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,16 @@ export const openMarket = async ({
* @returns {Promise<{ transaction: Transaction, result: { make: CurrencyFlow, take: CurrencyFlow, spent: CurrencyFlow }>}
* Promise resolving to the transaction object representing the limit order with the result of the order.
* @example
* import { signERC20Permit, limitOrder } from '@clober/v2-sdk'
* import { limitOrder } from '@clober/v2-sdk'
* import { privateKeyToAccount } from 'viem/accounts'
*
* const erc20PermitParam = await signERC20Permit({
* chainId: 421614,
* walletClient,
* token: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
* amount: '100.123'
* })
*
* const { transaction } = await limitOrder({
* chainId: 421614,
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
* outputToken: '0x0000000000000000000000000000000000000000',
* amount: '100.123', // 100.123 USDC
* price: '4000.01', // price at 4000.01 (ETH/USDC)
* options: { erc20PermitParam }
* })
*
* @example
Expand Down Expand Up @@ -444,16 +436,9 @@ export const limitOrder = async ({
* @returns {Promise<{ transaction: Transaction, result: { spent: CurrencyFlow, taken: CurrencyFlow } }>}
* Promise resolving to the transaction object representing the market order with the result of the order.
* @example
* import { signERC20Permit, marketOrder } from '@clober/v2-sdk'
* import { marketOrder } from '@clober/v2-sdk'
* import { privateKeyToAccount } from 'viem/accounts'
*
* const erc20PermitParam = await signERC20Permit({
* chainId: 421614,
* walletClient,
* token: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
* amount: '100.123'
* })
*
* const transaction = await marketOrder({
* chainId: 421614,
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './type'
export * from './view'
export * from './call'
export * from './signature'
export * from './approval'
export * from './utils'
196 changes: 0 additions & 196 deletions src/signature.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const getMarket = async ({
* @param chainId - chain id from {@link CHAIN_IDS}
* @param token0 - token0 address
* @param token1 - token1 address
* @param salt - salt for the pool
* @param options {@link DefaultOptions} options.
* @param options.n - number of depth levels to fetch
* @returns A pool {@link Pool}
Expand Down
Loading

0 comments on commit 80855c4

Please sign in to comment.