tempo.ts 0.11.1 → 0.12.1
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/CHANGELOG.md +67 -4
- package/README.md +3 -34
- package/dist/server/Handler.d.ts +14 -14
- package/dist/server/Handler.d.ts.map +1 -1
- package/dist/server/Handler.js +16 -17
- package/dist/server/Handler.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +51 -51
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +37 -37
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/dex.d.ts +129 -129
- package/dist/wagmi/Actions/dex.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.js +73 -73
- package/dist/wagmi/Actions/dex.js.map +1 -1
- package/dist/wagmi/Actions/faucet.d.ts +9 -9
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
- package/dist/wagmi/Actions/faucet.js +7 -7
- package/dist/wagmi/Actions/faucet.js.map +1 -1
- package/dist/wagmi/Actions/fee.d.ts +17 -17
- package/dist/wagmi/Actions/fee.d.ts.map +1 -1
- package/dist/wagmi/Actions/fee.js +10 -10
- package/dist/wagmi/Actions/fee.js.map +1 -1
- package/dist/wagmi/Actions/nonce.d.ts +9 -79
- package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
- package/dist/wagmi/Actions/nonce.js +7 -89
- package/dist/wagmi/Actions/nonce.js.map +1 -1
- package/dist/wagmi/Actions/policy.d.ts +69 -70
- package/dist/wagmi/Actions/policy.d.ts.map +1 -1
- package/dist/wagmi/Actions/policy.js +43 -43
- package/dist/wagmi/Actions/policy.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +51 -51
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +31 -31
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Actions/token.d.ts +238 -238
- package/dist/wagmi/Actions/token.d.ts.map +1 -1
- package/dist/wagmi/Actions/token.js +136 -136
- package/dist/wagmi/Actions/token.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +2 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +83 -22
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/nonce.d.ts +1 -52
- package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
- package/dist/wagmi/Hooks/nonce.js +1 -70
- package/dist/wagmi/Hooks/nonce.js.map +1 -1
- package/dist/wagmi/Hooks/policy.d.ts +0 -1
- package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
- package/dist/wagmi/Hooks/policy.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +6 -3
- package/dist/wagmi/KeyManager.d.ts.map +1 -1
- package/dist/wagmi/KeyManager.js +9 -4
- package/dist/wagmi/KeyManager.js.map +1 -1
- package/package.json +3 -13
- package/src/server/Handler.test.ts +2 -2
- package/src/server/Handler.ts +16 -17
- package/src/wagmi/Actions/amm.ts +63 -63
- package/src/wagmi/Actions/dex.test.ts +1 -1
- package/src/wagmi/Actions/dex.ts +153 -153
- package/src/wagmi/Actions/faucet.ts +11 -11
- package/src/wagmi/Actions/fee.ts +20 -20
- package/src/wagmi/Actions/nonce.test.ts +1 -64
- package/src/wagmi/Actions/nonce.ts +10 -142
- package/src/wagmi/Actions/policy.ts +83 -85
- package/src/wagmi/Actions/reward.ts +64 -61
- package/src/wagmi/Actions/token.ts +287 -283
- package/src/wagmi/Connector.ts +105 -31
- package/src/wagmi/Hooks/dex.test.ts +1 -1
- package/src/wagmi/Hooks/fee.test.ts +0 -6
- package/src/wagmi/Hooks/nonce.test.ts +1 -66
- package/src/wagmi/Hooks/nonce.ts +1 -114
- package/src/wagmi/Hooks/policy.ts +0 -2
- package/src/wagmi/KeyManager.ts +18 -5
- package/dist/chains.d.ts +0 -73
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -51
- package/dist/chains.js.map +0 -1
- package/dist/viem/Abis.d.ts +0 -2649
- package/dist/viem/Abis.d.ts.map +0 -1
- package/dist/viem/Abis.js +0 -1677
- package/dist/viem/Abis.js.map +0 -1
- package/dist/viem/Account.d.ts +0 -244
- package/dist/viem/Account.d.ts.map +0 -1
- package/dist/viem/Account.js +0 -382
- package/dist/viem/Account.js.map +0 -1
- package/dist/viem/Actions/account.d.ts +0 -40
- package/dist/viem/Actions/account.d.ts.map +0 -1
- package/dist/viem/Actions/account.js +0 -86
- package/dist/viem/Actions/account.js.map +0 -1
- package/dist/viem/Actions/amm.d.ts +0 -1991
- package/dist/viem/Actions/amm.d.ts.map +0 -1
- package/dist/viem/Actions/amm.js +0 -814
- package/dist/viem/Actions/amm.js.map +0 -1
- package/dist/viem/Actions/dex.d.ts +0 -3900
- package/dist/viem/Actions/dex.d.ts.map +0 -1
- package/dist/viem/Actions/dex.js +0 -1414
- package/dist/viem/Actions/dex.js.map +0 -1
- package/dist/viem/Actions/faucet.d.ts +0 -69
- package/dist/viem/Actions/faucet.d.ts.map +0 -1
- package/dist/viem/Actions/faucet.js +0 -73
- package/dist/viem/Actions/faucet.js.map +0 -1
- package/dist/viem/Actions/fee.d.ts +0 -360
- package/dist/viem/Actions/fee.d.ts.map +0 -1
- package/dist/viem/Actions/fee.js +0 -237
- package/dist/viem/Actions/fee.js.map +0 -1
- package/dist/viem/Actions/index.d.ts +0 -10
- package/dist/viem/Actions/index.d.ts.map +0 -1
- package/dist/viem/Actions/index.js +0 -10
- package/dist/viem/Actions/index.js.map +0 -1
- package/dist/viem/Actions/nonce.d.ts +0 -257
- package/dist/viem/Actions/nonce.d.ts.map +0 -1
- package/dist/viem/Actions/nonce.js +0 -228
- package/dist/viem/Actions/nonce.js.map +0 -1
- package/dist/viem/Actions/policy.d.ts +0 -1680
- package/dist/viem/Actions/policy.d.ts.map +0 -1
- package/dist/viem/Actions/policy.js +0 -875
- package/dist/viem/Actions/policy.js.map +0 -1
- package/dist/viem/Actions/reward.d.ts +0 -2422
- package/dist/viem/Actions/reward.d.ts.map +0 -1
- package/dist/viem/Actions/reward.js +0 -651
- package/dist/viem/Actions/reward.js.map +0 -1
- package/dist/viem/Actions/token.d.ts +0 -16007
- package/dist/viem/Actions/token.d.ts.map +0 -1
- package/dist/viem/Actions/token.js +0 -2936
- package/dist/viem/Actions/token.js.map +0 -1
- package/dist/viem/Addresses.d.ts +0 -9
- package/dist/viem/Addresses.d.ts.map +0 -1
- package/dist/viem/Addresses.js +0 -9
- package/dist/viem/Addresses.js.map +0 -1
- package/dist/viem/Chain.d.ts +0 -451
- package/dist/viem/Chain.d.ts.map +0 -1
- package/dist/viem/Chain.js +0 -96
- package/dist/viem/Chain.js.map +0 -1
- package/dist/viem/Decorator.d.ts +0 -2783
- package/dist/viem/Decorator.d.ts.map +0 -1
- package/dist/viem/Decorator.js +0 -137
- package/dist/viem/Decorator.js.map +0 -1
- package/dist/viem/Formatters.d.ts +0 -10
- package/dist/viem/Formatters.d.ts.map +0 -1
- package/dist/viem/Formatters.js +0 -104
- package/dist/viem/Formatters.js.map +0 -1
- package/dist/viem/P256.d.ts +0 -2
- package/dist/viem/P256.d.ts.map +0 -1
- package/dist/viem/P256.js +0 -2
- package/dist/viem/P256.js.map +0 -1
- package/dist/viem/Secp256k1.d.ts +0 -2
- package/dist/viem/Secp256k1.d.ts.map +0 -1
- package/dist/viem/Secp256k1.js +0 -2
- package/dist/viem/Secp256k1.js.map +0 -1
- package/dist/viem/Storage.d.ts +0 -24
- package/dist/viem/Storage.d.ts.map +0 -1
- package/dist/viem/Storage.js +0 -68
- package/dist/viem/Storage.js.map +0 -1
- package/dist/viem/TokenIds.d.ts +0 -2
- package/dist/viem/TokenIds.d.ts.map +0 -1
- package/dist/viem/TokenIds.js +0 -2
- package/dist/viem/TokenIds.js.map +0 -1
- package/dist/viem/Transaction.d.ts +0 -76
- package/dist/viem/Transaction.d.ts.map +0 -1
- package/dist/viem/Transaction.js +0 -176
- package/dist/viem/Transaction.js.map +0 -1
- package/dist/viem/Transport.d.ts +0 -33
- package/dist/viem/Transport.d.ts.map +0 -1
- package/dist/viem/Transport.js +0 -138
- package/dist/viem/Transport.js.map +0 -1
- package/dist/viem/WebAuthnP256.d.ts +0 -82
- package/dist/viem/WebAuthnP256.d.ts.map +0 -1
- package/dist/viem/WebAuthnP256.js +0 -97
- package/dist/viem/WebAuthnP256.js.map +0 -1
- package/dist/viem/WebCryptoP256.d.ts +0 -2
- package/dist/viem/WebCryptoP256.d.ts.map +0 -1
- package/dist/viem/WebCryptoP256.js +0 -2
- package/dist/viem/WebCryptoP256.js.map +0 -1
- package/dist/viem/index.d.ts +0 -26
- package/dist/viem/index.d.ts.map +0 -1
- package/dist/viem/index.js +0 -17
- package/dist/viem/index.js.map +0 -1
- package/dist/viem/internal/types.d.ts +0 -20
- package/dist/viem/internal/types.d.ts.map +0 -1
- package/dist/viem/internal/types.js +0 -2
- package/dist/viem/internal/types.js.map +0 -1
- package/dist/viem/internal/utils.d.ts +0 -14
- package/dist/viem/internal/utils.d.ts.map +0 -1
- package/dist/viem/internal/utils.js +0 -33
- package/dist/viem/internal/utils.js.map +0 -1
- package/src/chains.ts +0 -54
- package/src/viem/Abis.ts +0 -1688
- package/src/viem/Account.test.ts +0 -444
- package/src/viem/Account.ts +0 -601
- package/src/viem/Actions/account.test.ts +0 -414
- package/src/viem/Actions/account.ts +0 -106
- package/src/viem/Actions/amm.test.ts +0 -381
- package/src/viem/Actions/amm.ts +0 -1227
- package/src/viem/Actions/dex.test.ts +0 -1549
- package/src/viem/Actions/dex.ts +0 -2150
- package/src/viem/Actions/faucet.ts +0 -121
- package/src/viem/Actions/fee.test.ts +0 -259
- package/src/viem/Actions/fee.ts +0 -372
- package/src/viem/Actions/index.ts +0 -9
- package/src/viem/Actions/nonce.test.ts +0 -206
- package/src/viem/Actions/nonce.ts +0 -347
- package/src/viem/Actions/policy.test.ts +0 -534
- package/src/viem/Actions/policy.ts +0 -1335
- package/src/viem/Actions/reward.test.ts +0 -434
- package/src/viem/Actions/reward.ts +0 -944
- package/src/viem/Actions/token.test.ts +0 -3029
- package/src/viem/Actions/token.ts +0 -4458
- package/src/viem/Addresses.ts +0 -9
- package/src/viem/Chain.bench-d.ts +0 -12
- package/src/viem/Chain.test.ts +0 -168
- package/src/viem/Chain.ts +0 -157
- package/src/viem/Decorator.bench-d.ts +0 -11
- package/src/viem/Decorator.test.ts +0 -39
- package/src/viem/Decorator.ts +0 -3179
- package/src/viem/Formatters.ts +0 -164
- package/src/viem/P256.ts +0 -1
- package/src/viem/Secp256k1.ts +0 -1
- package/src/viem/Storage.ts +0 -110
- package/src/viem/TokenIds.ts +0 -1
- package/src/viem/Transaction.ts +0 -382
- package/src/viem/Transport.ts +0 -191
- package/src/viem/WebAuthnP256.ts +0 -146
- package/src/viem/WebCryptoP256.ts +0 -1
- package/src/viem/e2e.test.ts +0 -1602
- package/src/viem/index.ts +0 -30
- package/src/viem/internal/types.ts +0 -69
- package/src/viem/internal/utils.ts +0 -58
- package/src/wagmi/internal/types.ts +0 -16
package/src/viem/Actions/dex.ts
DELETED
|
@@ -1,2150 +0,0 @@
|
|
|
1
|
-
import * as Hash from 'ox/Hash'
|
|
2
|
-
import * as Hex from 'ox/Hex'
|
|
3
|
-
import {
|
|
4
|
-
type Account,
|
|
5
|
-
type Address,
|
|
6
|
-
type BaseErrorType,
|
|
7
|
-
type Chain,
|
|
8
|
-
type Client,
|
|
9
|
-
type ExtractAbiItem,
|
|
10
|
-
type GetEventArgs,
|
|
11
|
-
type Log,
|
|
12
|
-
parseEventLogs,
|
|
13
|
-
type ReadContractReturnType,
|
|
14
|
-
type TransactionReceipt,
|
|
15
|
-
type Transport,
|
|
16
|
-
type Log as viem_Log,
|
|
17
|
-
type WatchContractEventParameters,
|
|
18
|
-
type WriteContractReturnType,
|
|
19
|
-
} from 'viem'
|
|
20
|
-
import { parseAccount } from 'viem/accounts'
|
|
21
|
-
import {
|
|
22
|
-
readContract,
|
|
23
|
-
watchContractEvent,
|
|
24
|
-
writeContract,
|
|
25
|
-
writeContractSync,
|
|
26
|
-
} from 'viem/actions'
|
|
27
|
-
import type { Compute, UnionOmit } from '../../internal/types.js'
|
|
28
|
-
import * as Abis from '../Abis.js'
|
|
29
|
-
import * as Addresses from '../Addresses.js'
|
|
30
|
-
import type {
|
|
31
|
-
GetAccountParameter,
|
|
32
|
-
ReadParameters,
|
|
33
|
-
WriteParameters,
|
|
34
|
-
} from '../internal/types.js'
|
|
35
|
-
import { defineCall } from '../internal/utils.js'
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Order type for limit orders.
|
|
39
|
-
*/
|
|
40
|
-
type OrderType = 'buy' | 'sell'
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Buys a specific amount of tokens.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
48
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
49
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
50
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
51
|
-
*
|
|
52
|
-
* const client = createClient({
|
|
53
|
-
* account: privateKeyToAccount('0x...'),
|
|
54
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
55
|
-
* transport: http(),
|
|
56
|
-
* })
|
|
57
|
-
*
|
|
58
|
-
* const hash = await Actions.dex.buy(client, {
|
|
59
|
-
* tokenIn: '0x20c...11',
|
|
60
|
-
* tokenOut: '0x20c...20',
|
|
61
|
-
* amountOut: parseUnits('100', 6),
|
|
62
|
-
* maxAmountIn: parseUnits('105', 6),
|
|
63
|
-
* })
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @param client - Client.
|
|
67
|
-
* @param parameters - Parameters.
|
|
68
|
-
* @returns The transaction hash.
|
|
69
|
-
*/
|
|
70
|
-
export async function buy<
|
|
71
|
-
chain extends Chain | undefined,
|
|
72
|
-
account extends Account | undefined,
|
|
73
|
-
>(
|
|
74
|
-
client: Client<Transport, chain, account>,
|
|
75
|
-
parameters: buy.Parameters<chain, account>,
|
|
76
|
-
): Promise<buy.ReturnValue> {
|
|
77
|
-
return buy.inner(writeContract, client, parameters)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export namespace buy {
|
|
81
|
-
export type Parameters<
|
|
82
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
83
|
-
account extends Account | undefined = Account | undefined,
|
|
84
|
-
> = WriteParameters<chain, account> & Args
|
|
85
|
-
|
|
86
|
-
export type Args = {
|
|
87
|
-
/** Amount of tokenOut to buy. */
|
|
88
|
-
amountOut: bigint
|
|
89
|
-
/** Maximum amount of tokenIn to spend. */
|
|
90
|
-
maxAmountIn: bigint
|
|
91
|
-
/** Address of the token to spend. */
|
|
92
|
-
tokenIn: Address
|
|
93
|
-
/** Address of the token to buy. */
|
|
94
|
-
tokenOut: Address
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export type ReturnValue = WriteContractReturnType
|
|
98
|
-
|
|
99
|
-
// TODO: exhaustive error type
|
|
100
|
-
export type ErrorType = BaseErrorType
|
|
101
|
-
|
|
102
|
-
/** @internal */
|
|
103
|
-
export async function inner<
|
|
104
|
-
action extends typeof writeContract | typeof writeContractSync,
|
|
105
|
-
chain extends Chain | undefined,
|
|
106
|
-
account extends Account | undefined,
|
|
107
|
-
>(
|
|
108
|
-
action: action,
|
|
109
|
-
client: Client<Transport, chain, account>,
|
|
110
|
-
parameters: buy.Parameters<chain, account>,
|
|
111
|
-
): Promise<ReturnType<action>> {
|
|
112
|
-
const { tokenIn, tokenOut, amountOut, maxAmountIn, ...rest } = parameters
|
|
113
|
-
const call = buy.call({ tokenIn, tokenOut, amountOut, maxAmountIn })
|
|
114
|
-
return (await action(client, {
|
|
115
|
-
...rest,
|
|
116
|
-
...call,
|
|
117
|
-
} as never)) as never
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Defines a call to the `swapExactAmountOut` function.
|
|
122
|
-
*
|
|
123
|
-
* Can be passed as a parameter to:
|
|
124
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
125
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
126
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* import { createClient, http, parseUnits, walletActions } from 'viem'
|
|
131
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
132
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
133
|
-
*
|
|
134
|
-
* const client = createClient({
|
|
135
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
136
|
-
* transport: http(),
|
|
137
|
-
* }).extend(walletActions)
|
|
138
|
-
*
|
|
139
|
-
* const { result } = await client.sendCalls({
|
|
140
|
-
* calls: [
|
|
141
|
-
* Actions.dex.buy.call({
|
|
142
|
-
* tokenIn: '0x20c0...beef',
|
|
143
|
-
* tokenOut: '0x20c0...babe',
|
|
144
|
-
* amountOut: parseUnits('100', 6),
|
|
145
|
-
* maxAmountIn: parseUnits('105', 6),
|
|
146
|
-
* }),
|
|
147
|
-
* ]
|
|
148
|
-
* })
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
* @param args - Arguments.
|
|
152
|
-
* @returns The call.
|
|
153
|
-
*/
|
|
154
|
-
export function call(args: Args) {
|
|
155
|
-
const { tokenIn, tokenOut, amountOut, maxAmountIn } = args
|
|
156
|
-
return defineCall({
|
|
157
|
-
address: Addresses.stablecoinExchange,
|
|
158
|
-
abi: Abis.stablecoinExchange,
|
|
159
|
-
functionName: 'swapExactAmountOut',
|
|
160
|
-
args: [tokenIn, tokenOut, amountOut, maxAmountIn],
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Buys a specific amount of tokens.
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```ts
|
|
170
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
171
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
172
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
173
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
174
|
-
*
|
|
175
|
-
* const client = createClient({
|
|
176
|
-
* account: privateKeyToAccount('0x...'),
|
|
177
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
178
|
-
* transport: http(),
|
|
179
|
-
* })
|
|
180
|
-
*
|
|
181
|
-
* const result = await Actions.dex.buySync(client, {
|
|
182
|
-
* tokenIn: '0x20c...11',
|
|
183
|
-
* tokenOut: '0x20c...20',
|
|
184
|
-
* amountOut: parseUnits('100', 6),
|
|
185
|
-
* maxAmountIn: parseUnits('105', 6),
|
|
186
|
-
* })
|
|
187
|
-
* ```
|
|
188
|
-
*
|
|
189
|
-
* @param client - Client.
|
|
190
|
-
* @param parameters - Parameters.
|
|
191
|
-
* @returns The transaction receipt.
|
|
192
|
-
*/
|
|
193
|
-
export async function buySync<
|
|
194
|
-
chain extends Chain | undefined,
|
|
195
|
-
account extends Account | undefined,
|
|
196
|
-
>(
|
|
197
|
-
client: Client<Transport, chain, account>,
|
|
198
|
-
parameters: buySync.Parameters<chain, account>,
|
|
199
|
-
): Promise<buySync.ReturnValue> {
|
|
200
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
201
|
-
const receipt = await buy.inner(writeContractSync, client, {
|
|
202
|
-
...rest,
|
|
203
|
-
throwOnReceiptRevert,
|
|
204
|
-
} as never)
|
|
205
|
-
return { receipt }
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export namespace buySync {
|
|
209
|
-
export type Parameters<
|
|
210
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
211
|
-
account extends Account | undefined = Account | undefined,
|
|
212
|
-
> = buy.Parameters<chain, account>
|
|
213
|
-
|
|
214
|
-
export type Args = buy.Args
|
|
215
|
-
|
|
216
|
-
export type ReturnValue = Compute<{
|
|
217
|
-
/** Transaction receipt. */
|
|
218
|
-
receipt: TransactionReceipt
|
|
219
|
-
}>
|
|
220
|
-
|
|
221
|
-
// TODO: exhaustive error type
|
|
222
|
-
export type ErrorType = BaseErrorType
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Cancels an order from the orderbook.
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```ts
|
|
230
|
-
* import { createClient, http } from 'viem'
|
|
231
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
232
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
233
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
234
|
-
*
|
|
235
|
-
* const client = createClient({
|
|
236
|
-
* account: privateKeyToAccount('0x...'),
|
|
237
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
238
|
-
* transport: http(),
|
|
239
|
-
* })
|
|
240
|
-
*
|
|
241
|
-
* const hash = await Actions.dex.cancel(client, {
|
|
242
|
-
* orderId: 123n,
|
|
243
|
-
* })
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* @param client - Client.
|
|
247
|
-
* @param parameters - Parameters.
|
|
248
|
-
* @returns The transaction hash.
|
|
249
|
-
*/
|
|
250
|
-
export async function cancel<
|
|
251
|
-
chain extends Chain | undefined,
|
|
252
|
-
account extends Account | undefined,
|
|
253
|
-
>(
|
|
254
|
-
client: Client<Transport, chain, account>,
|
|
255
|
-
parameters: cancel.Parameters<chain, account>,
|
|
256
|
-
): Promise<cancel.ReturnValue> {
|
|
257
|
-
return cancel.inner(writeContract, client, parameters)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export namespace cancel {
|
|
261
|
-
export type Parameters<
|
|
262
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
263
|
-
account extends Account | undefined = Account | undefined,
|
|
264
|
-
> = WriteParameters<chain, account> & Args
|
|
265
|
-
|
|
266
|
-
export type Args = {
|
|
267
|
-
/** Order ID to cancel. */
|
|
268
|
-
orderId: bigint
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export type ReturnValue = WriteContractReturnType
|
|
272
|
-
|
|
273
|
-
// TODO: exhaustive error type
|
|
274
|
-
export type ErrorType = BaseErrorType
|
|
275
|
-
|
|
276
|
-
/** @internal */
|
|
277
|
-
export async function inner<
|
|
278
|
-
action extends typeof writeContract | typeof writeContractSync,
|
|
279
|
-
chain extends Chain | undefined,
|
|
280
|
-
account extends Account | undefined,
|
|
281
|
-
>(
|
|
282
|
-
action: action,
|
|
283
|
-
client: Client<Transport, chain, account>,
|
|
284
|
-
parameters: cancel.Parameters<chain, account>,
|
|
285
|
-
): Promise<ReturnType<action>> {
|
|
286
|
-
const { orderId, ...rest } = parameters
|
|
287
|
-
const call = cancel.call({ orderId })
|
|
288
|
-
return (await action(client, {
|
|
289
|
-
...rest,
|
|
290
|
-
...call,
|
|
291
|
-
} as never)) as never
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Defines a call to the `cancel` function.
|
|
296
|
-
*
|
|
297
|
-
* Can be passed as a parameter to:
|
|
298
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
299
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
300
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
301
|
-
*
|
|
302
|
-
* @example
|
|
303
|
-
* ```ts
|
|
304
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
305
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
306
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
307
|
-
*
|
|
308
|
-
* const client = createClient({
|
|
309
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
310
|
-
* transport: http(),
|
|
311
|
-
* }).extend(walletActions)
|
|
312
|
-
*
|
|
313
|
-
* const { result } = await client.sendCalls({
|
|
314
|
-
* calls: [
|
|
315
|
-
* Actions.dex.cancel.call({
|
|
316
|
-
* orderId: 123n,
|
|
317
|
-
* }),
|
|
318
|
-
* ]
|
|
319
|
-
* })
|
|
320
|
-
* ```
|
|
321
|
-
*
|
|
322
|
-
* @param args - Arguments.
|
|
323
|
-
* @returns The call.
|
|
324
|
-
*/
|
|
325
|
-
export function call(args: Args) {
|
|
326
|
-
const { orderId } = args
|
|
327
|
-
return defineCall({
|
|
328
|
-
address: Addresses.stablecoinExchange,
|
|
329
|
-
abi: Abis.stablecoinExchange,
|
|
330
|
-
functionName: 'cancel',
|
|
331
|
-
args: [orderId],
|
|
332
|
-
})
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Extracts the `OrderCancelled` event from logs.
|
|
337
|
-
*
|
|
338
|
-
* @param logs - The logs.
|
|
339
|
-
* @returns The `OrderCancelled` event.
|
|
340
|
-
*/
|
|
341
|
-
export function extractEvent(logs: Log[]) {
|
|
342
|
-
const [log] = parseEventLogs({
|
|
343
|
-
abi: Abis.stablecoinExchange,
|
|
344
|
-
logs,
|
|
345
|
-
eventName: 'OrderCancelled',
|
|
346
|
-
strict: true,
|
|
347
|
-
})
|
|
348
|
-
if (!log) throw new Error('`OrderCancelled` event not found.')
|
|
349
|
-
return log
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Cancels an order from the orderbook.
|
|
355
|
-
*
|
|
356
|
-
* @example
|
|
357
|
-
* ```ts
|
|
358
|
-
* import { createClient, http } from 'viem'
|
|
359
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
360
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
361
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
362
|
-
*
|
|
363
|
-
* const client = createClient({
|
|
364
|
-
* account: privateKeyToAccount('0x...'),
|
|
365
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
366
|
-
* transport: http(),
|
|
367
|
-
* })
|
|
368
|
-
*
|
|
369
|
-
* const result = await Actions.dex.cancelSync(client, {
|
|
370
|
-
* orderId: 123n,
|
|
371
|
-
* })
|
|
372
|
-
* ```
|
|
373
|
-
*
|
|
374
|
-
* @param client - Client.
|
|
375
|
-
* @param parameters - Parameters.
|
|
376
|
-
* @returns The transaction receipt and event data.
|
|
377
|
-
*/
|
|
378
|
-
export async function cancelSync<
|
|
379
|
-
chain extends Chain | undefined,
|
|
380
|
-
account extends Account | undefined,
|
|
381
|
-
>(
|
|
382
|
-
client: Client<Transport, chain, account>,
|
|
383
|
-
parameters: cancelSync.Parameters<chain, account>,
|
|
384
|
-
): Promise<cancelSync.ReturnValue> {
|
|
385
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
386
|
-
const receipt = await cancel.inner(writeContractSync, client, {
|
|
387
|
-
...rest,
|
|
388
|
-
throwOnReceiptRevert,
|
|
389
|
-
} as never)
|
|
390
|
-
const { args } = cancel.extractEvent(receipt.logs)
|
|
391
|
-
return {
|
|
392
|
-
...args,
|
|
393
|
-
receipt,
|
|
394
|
-
} as never
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
export namespace cancelSync {
|
|
398
|
-
export type Parameters<
|
|
399
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
400
|
-
account extends Account | undefined = Account | undefined,
|
|
401
|
-
> = cancel.Parameters<chain, account>
|
|
402
|
-
|
|
403
|
-
export type Args = cancel.Args
|
|
404
|
-
|
|
405
|
-
export type ReturnValue = Compute<
|
|
406
|
-
GetEventArgs<
|
|
407
|
-
typeof Abis.stablecoinExchange,
|
|
408
|
-
'OrderCancelled',
|
|
409
|
-
{ IndexedOnly: false; Required: true }
|
|
410
|
-
> & {
|
|
411
|
-
/** Transaction receipt. */
|
|
412
|
-
receipt: TransactionReceipt
|
|
413
|
-
}
|
|
414
|
-
>
|
|
415
|
-
|
|
416
|
-
// TODO: exhaustive error type
|
|
417
|
-
export type ErrorType = BaseErrorType
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Creates a new trading pair on the DEX.
|
|
422
|
-
*
|
|
423
|
-
* @example
|
|
424
|
-
* ```ts
|
|
425
|
-
* import { createClient, http } from 'viem'
|
|
426
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
427
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
428
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
429
|
-
*
|
|
430
|
-
* const client = createClient({
|
|
431
|
-
* account: privateKeyToAccount('0x...'),
|
|
432
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
433
|
-
* transport: http(),
|
|
434
|
-
* })
|
|
435
|
-
*
|
|
436
|
-
* const hash = await Actions.dex.createPair(client, {
|
|
437
|
-
* base: '0x20c...11',
|
|
438
|
-
* })
|
|
439
|
-
* ```
|
|
440
|
-
*
|
|
441
|
-
* @param client - Client.
|
|
442
|
-
* @param parameters - Parameters.
|
|
443
|
-
* @returns The transaction hash.
|
|
444
|
-
*/
|
|
445
|
-
export async function createPair<
|
|
446
|
-
chain extends Chain | undefined,
|
|
447
|
-
account extends Account | undefined,
|
|
448
|
-
>(
|
|
449
|
-
client: Client<Transport, chain, account>,
|
|
450
|
-
parameters: createPair.Parameters<chain, account>,
|
|
451
|
-
): Promise<createPair.ReturnValue> {
|
|
452
|
-
return createPair.inner(writeContract, client, parameters)
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
export namespace createPair {
|
|
456
|
-
export type Parameters<
|
|
457
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
458
|
-
account extends Account | undefined = Account | undefined,
|
|
459
|
-
> = WriteParameters<chain, account> & Args
|
|
460
|
-
|
|
461
|
-
export type Args = {
|
|
462
|
-
/** Address of the base token for the pair. */
|
|
463
|
-
base: Address
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
export type ReturnValue = WriteContractReturnType
|
|
467
|
-
|
|
468
|
-
// TODO: exhaustive error type
|
|
469
|
-
export type ErrorType = BaseErrorType
|
|
470
|
-
|
|
471
|
-
/** @internal */
|
|
472
|
-
export async function inner<
|
|
473
|
-
action extends typeof writeContract | typeof writeContractSync,
|
|
474
|
-
chain extends Chain | undefined,
|
|
475
|
-
account extends Account | undefined,
|
|
476
|
-
>(
|
|
477
|
-
action: action,
|
|
478
|
-
client: Client<Transport, chain, account>,
|
|
479
|
-
parameters: createPair.Parameters<chain, account>,
|
|
480
|
-
): Promise<ReturnType<action>> {
|
|
481
|
-
const { base, ...rest } = parameters
|
|
482
|
-
const call = createPair.call({ base })
|
|
483
|
-
return (await action(client, {
|
|
484
|
-
...rest,
|
|
485
|
-
...call,
|
|
486
|
-
} as never)) as never
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Defines a call to the `createPair` function.
|
|
491
|
-
*
|
|
492
|
-
* Can be passed as a parameter to:
|
|
493
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
494
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
495
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
496
|
-
*
|
|
497
|
-
* @example
|
|
498
|
-
* ```ts
|
|
499
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
500
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
501
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
502
|
-
*
|
|
503
|
-
* const client = createClient({
|
|
504
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
505
|
-
* transport: http(),
|
|
506
|
-
* }).extend(walletActions)
|
|
507
|
-
*
|
|
508
|
-
* const { result } = await client.sendCalls({
|
|
509
|
-
* calls: [
|
|
510
|
-
* Actions.dex.createPair.call({
|
|
511
|
-
* base: '0x20c0...beef',
|
|
512
|
-
* }),
|
|
513
|
-
* ]
|
|
514
|
-
* })
|
|
515
|
-
* ```
|
|
516
|
-
*
|
|
517
|
-
* @param args - Arguments.
|
|
518
|
-
* @returns The call.
|
|
519
|
-
*/
|
|
520
|
-
export function call(args: Args) {
|
|
521
|
-
const { base } = args
|
|
522
|
-
return defineCall({
|
|
523
|
-
address: Addresses.stablecoinExchange,
|
|
524
|
-
abi: Abis.stablecoinExchange,
|
|
525
|
-
functionName: 'createPair',
|
|
526
|
-
args: [base],
|
|
527
|
-
})
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Extracts the `PairCreated` event from logs.
|
|
532
|
-
*
|
|
533
|
-
* @param logs - The logs.
|
|
534
|
-
* @returns The `PairCreated` event.
|
|
535
|
-
*/
|
|
536
|
-
export function extractEvent(logs: Log[]) {
|
|
537
|
-
const [log] = parseEventLogs({
|
|
538
|
-
abi: Abis.stablecoinExchange,
|
|
539
|
-
logs,
|
|
540
|
-
eventName: 'PairCreated',
|
|
541
|
-
strict: true,
|
|
542
|
-
})
|
|
543
|
-
if (!log) throw new Error('`PairCreated` event not found.')
|
|
544
|
-
return log
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* Creates a new trading pair on the DEX.
|
|
550
|
-
*
|
|
551
|
-
* @example
|
|
552
|
-
* ```ts
|
|
553
|
-
* import { createClient, http } from 'viem'
|
|
554
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
555
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
556
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
557
|
-
*
|
|
558
|
-
* const client = createClient({
|
|
559
|
-
* account: privateKeyToAccount('0x...'),
|
|
560
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
561
|
-
* transport: http(),
|
|
562
|
-
* })
|
|
563
|
-
*
|
|
564
|
-
* const result = await Actions.dex.createPairSync(client, {
|
|
565
|
-
* base: '0x20c...11',
|
|
566
|
-
* })
|
|
567
|
-
* ```
|
|
568
|
-
*
|
|
569
|
-
* @param client - Client.
|
|
570
|
-
* @param parameters - Parameters.
|
|
571
|
-
* @returns The transaction receipt and event data.
|
|
572
|
-
*/
|
|
573
|
-
export async function createPairSync<
|
|
574
|
-
chain extends Chain | undefined,
|
|
575
|
-
account extends Account | undefined,
|
|
576
|
-
>(
|
|
577
|
-
client: Client<Transport, chain, account>,
|
|
578
|
-
parameters: createPairSync.Parameters<chain, account>,
|
|
579
|
-
): Promise<createPairSync.ReturnValue> {
|
|
580
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
581
|
-
const receipt = await createPair.inner(writeContractSync, client, {
|
|
582
|
-
...rest,
|
|
583
|
-
throwOnReceiptRevert,
|
|
584
|
-
} as never)
|
|
585
|
-
const { args } = createPair.extractEvent(receipt.logs)
|
|
586
|
-
return {
|
|
587
|
-
...args,
|
|
588
|
-
receipt,
|
|
589
|
-
} as never
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
export namespace createPairSync {
|
|
593
|
-
export type Parameters<
|
|
594
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
595
|
-
account extends Account | undefined = Account | undefined,
|
|
596
|
-
> = createPair.Parameters<chain, account>
|
|
597
|
-
|
|
598
|
-
export type Args = createPair.Args
|
|
599
|
-
|
|
600
|
-
export type ReturnValue = Compute<
|
|
601
|
-
GetEventArgs<
|
|
602
|
-
typeof Abis.stablecoinExchange,
|
|
603
|
-
'PairCreated',
|
|
604
|
-
{ IndexedOnly: false; Required: true }
|
|
605
|
-
> & {
|
|
606
|
-
/** Transaction receipt. */
|
|
607
|
-
receipt: TransactionReceipt
|
|
608
|
-
}
|
|
609
|
-
>
|
|
610
|
-
|
|
611
|
-
// TODO: exhaustive error type
|
|
612
|
-
export type ErrorType = BaseErrorType
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Gets a user's token balance on the DEX.
|
|
617
|
-
*
|
|
618
|
-
* @example
|
|
619
|
-
* ```ts
|
|
620
|
-
* import { createClient, http } from 'viem'
|
|
621
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
622
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
623
|
-
*
|
|
624
|
-
* const client = createClient({
|
|
625
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
626
|
-
* transport: http(),
|
|
627
|
-
* })
|
|
628
|
-
*
|
|
629
|
-
* const balance = await Actions.dex.getBalance(client, {
|
|
630
|
-
* account: '0x...',
|
|
631
|
-
* token: '0x20c...11',
|
|
632
|
-
* })
|
|
633
|
-
* ```
|
|
634
|
-
*
|
|
635
|
-
* @param client - Client.
|
|
636
|
-
* @param parameters - Parameters.
|
|
637
|
-
* @returns The user's token balance on the DEX.
|
|
638
|
-
*/
|
|
639
|
-
export async function getBalance<
|
|
640
|
-
chain extends Chain | undefined,
|
|
641
|
-
account extends Account | undefined,
|
|
642
|
-
>(
|
|
643
|
-
client: Client<Transport, chain, account>,
|
|
644
|
-
parameters: getBalance.Parameters<account>,
|
|
645
|
-
): Promise<getBalance.ReturnValue> {
|
|
646
|
-
const { account: acc = client.account, token, ...rest } = parameters
|
|
647
|
-
const address = acc ? parseAccount(acc).address : undefined
|
|
648
|
-
if (!address) throw new Error('account is required.')
|
|
649
|
-
return readContract(client, {
|
|
650
|
-
...rest,
|
|
651
|
-
...getBalance.call({ account: address, token }),
|
|
652
|
-
})
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
export namespace getBalance {
|
|
656
|
-
export type Parameters<
|
|
657
|
-
account extends Account | undefined = Account | undefined,
|
|
658
|
-
> = ReadParameters & GetAccountParameter<account> & Args
|
|
659
|
-
|
|
660
|
-
export type Args = {
|
|
661
|
-
/** Address of the account. */
|
|
662
|
-
account: Address
|
|
663
|
-
/** Address of the token. */
|
|
664
|
-
token: Address
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
export type ReturnValue = ReadContractReturnType<
|
|
668
|
-
typeof Abis.stablecoinExchange,
|
|
669
|
-
'balanceOf',
|
|
670
|
-
never
|
|
671
|
-
>
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Defines a call to the `balanceOf` function.
|
|
675
|
-
*
|
|
676
|
-
* @param args - Arguments.
|
|
677
|
-
* @returns The call.
|
|
678
|
-
*/
|
|
679
|
-
export function call(args: Args) {
|
|
680
|
-
const { account, token } = args
|
|
681
|
-
return defineCall({
|
|
682
|
-
address: Addresses.stablecoinExchange,
|
|
683
|
-
abi: Abis.stablecoinExchange,
|
|
684
|
-
args: [account, token],
|
|
685
|
-
functionName: 'balanceOf',
|
|
686
|
-
})
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* Gets the quote for buying a specific amount of tokens.
|
|
692
|
-
*
|
|
693
|
-
* @example
|
|
694
|
-
* ```ts
|
|
695
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
696
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
697
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
698
|
-
*
|
|
699
|
-
* const client = createClient({
|
|
700
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
701
|
-
* transport: http(),
|
|
702
|
-
* })
|
|
703
|
-
*
|
|
704
|
-
* const amountIn = await Actions.dex.getBuyQuote(client, {
|
|
705
|
-
* amountOut: parseUnits('100', 6),
|
|
706
|
-
* tokenIn: '0x20c...11',
|
|
707
|
-
* tokenOut: '0x20c...20',
|
|
708
|
-
* })
|
|
709
|
-
* ```
|
|
710
|
-
*
|
|
711
|
-
* @param client - Client.
|
|
712
|
-
* @param parameters - Parameters.
|
|
713
|
-
* @returns The amount of tokenIn needed to buy the specified amountOut.
|
|
714
|
-
*/
|
|
715
|
-
export async function getBuyQuote<chain extends Chain | undefined>(
|
|
716
|
-
client: Client<Transport, chain>,
|
|
717
|
-
parameters: getBuyQuote.Parameters,
|
|
718
|
-
): Promise<getBuyQuote.ReturnValue> {
|
|
719
|
-
const { tokenIn, tokenOut, amountOut, ...rest } = parameters
|
|
720
|
-
return readContract(client, {
|
|
721
|
-
...rest,
|
|
722
|
-
...getBuyQuote.call({ tokenIn, tokenOut, amountOut }),
|
|
723
|
-
})
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
export namespace getBuyQuote {
|
|
727
|
-
export type Parameters = ReadParameters & Args
|
|
728
|
-
|
|
729
|
-
export type Args = {
|
|
730
|
-
/** Amount of tokenOut to buy. */
|
|
731
|
-
amountOut: bigint
|
|
732
|
-
/** Address of the token to spend. */
|
|
733
|
-
tokenIn: Address
|
|
734
|
-
/** Address of the token to buy. */
|
|
735
|
-
tokenOut: Address
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
export type ReturnValue = ReadContractReturnType<
|
|
739
|
-
typeof Abis.stablecoinExchange,
|
|
740
|
-
'quoteSwapExactAmountOut',
|
|
741
|
-
never
|
|
742
|
-
>
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Defines a call to the `quoteSwapExactAmountOut` function.
|
|
746
|
-
*
|
|
747
|
-
* @param args - Arguments.
|
|
748
|
-
* @returns The call.
|
|
749
|
-
*/
|
|
750
|
-
export function call(args: Args) {
|
|
751
|
-
const { tokenIn, tokenOut, amountOut } = args
|
|
752
|
-
return defineCall({
|
|
753
|
-
address: Addresses.stablecoinExchange,
|
|
754
|
-
abi: Abis.stablecoinExchange,
|
|
755
|
-
args: [tokenIn, tokenOut, amountOut],
|
|
756
|
-
functionName: 'quoteSwapExactAmountOut',
|
|
757
|
-
})
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Gets an order's details from the orderbook.
|
|
763
|
-
*
|
|
764
|
-
* @example
|
|
765
|
-
* ```ts
|
|
766
|
-
* import { createClient, http } from 'viem'
|
|
767
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
768
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
769
|
-
*
|
|
770
|
-
* const client = createClient({
|
|
771
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
772
|
-
* transport: http(),
|
|
773
|
-
* })
|
|
774
|
-
*
|
|
775
|
-
* const order = await Actions.dex.getOrder(client, {
|
|
776
|
-
* orderId: 123n,
|
|
777
|
-
* })
|
|
778
|
-
* ```
|
|
779
|
-
*
|
|
780
|
-
* @param client - Client.
|
|
781
|
-
* @param parameters - Parameters.
|
|
782
|
-
* @returns The order details.
|
|
783
|
-
*/
|
|
784
|
-
export async function getOrder<chain extends Chain | undefined>(
|
|
785
|
-
client: Client<Transport, chain>,
|
|
786
|
-
parameters: getOrder.Parameters,
|
|
787
|
-
): Promise<getOrder.ReturnValue> {
|
|
788
|
-
const { orderId, ...rest } = parameters
|
|
789
|
-
return readContract(client, {
|
|
790
|
-
...rest,
|
|
791
|
-
...getOrder.call({ orderId }),
|
|
792
|
-
})
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
export namespace getOrder {
|
|
796
|
-
export type Parameters = ReadParameters & Args
|
|
797
|
-
|
|
798
|
-
export type Args = {
|
|
799
|
-
/** Order ID to query. */
|
|
800
|
-
orderId: bigint
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
export type ReturnValue = ReadContractReturnType<
|
|
804
|
-
typeof Abis.stablecoinExchange,
|
|
805
|
-
'getOrder',
|
|
806
|
-
never
|
|
807
|
-
>
|
|
808
|
-
|
|
809
|
-
/**
|
|
810
|
-
* Defines a call to the `getOrder` function.
|
|
811
|
-
*
|
|
812
|
-
* @param args - Arguments.
|
|
813
|
-
* @returns The call.
|
|
814
|
-
*/
|
|
815
|
-
export function call(args: Args) {
|
|
816
|
-
const { orderId } = args
|
|
817
|
-
return defineCall({
|
|
818
|
-
address: Addresses.stablecoinExchange,
|
|
819
|
-
abi: Abis.stablecoinExchange,
|
|
820
|
-
args: [orderId],
|
|
821
|
-
functionName: 'getOrder',
|
|
822
|
-
})
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
/**
|
|
827
|
-
* Gets orderbook information for a trading pair.
|
|
828
|
-
*
|
|
829
|
-
* @example
|
|
830
|
-
* ```ts
|
|
831
|
-
* import { createClient, http } from 'viem'
|
|
832
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
833
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
834
|
-
*
|
|
835
|
-
* const client = createClient({
|
|
836
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
837
|
-
* transport: http(),
|
|
838
|
-
* })
|
|
839
|
-
*
|
|
840
|
-
* const book = await Actions.dex.getOrderbook(client, {
|
|
841
|
-
* base: '0x20c...11',
|
|
842
|
-
* quote: '0x20c...20',
|
|
843
|
-
* })
|
|
844
|
-
* ```
|
|
845
|
-
*
|
|
846
|
-
* @param client - Client.
|
|
847
|
-
* @param parameters - Parameters.
|
|
848
|
-
* @returns The orderbook information.
|
|
849
|
-
*/
|
|
850
|
-
export async function getOrderbook<chain extends Chain | undefined>(
|
|
851
|
-
client: Client<Transport, chain>,
|
|
852
|
-
parameters: getOrderbook.Parameters,
|
|
853
|
-
): Promise<getOrderbook.ReturnValue> {
|
|
854
|
-
const { base, quote, ...rest } = parameters
|
|
855
|
-
return readContract(client, {
|
|
856
|
-
...rest,
|
|
857
|
-
...getOrderbook.call({ base, quote }),
|
|
858
|
-
})
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
export namespace getOrderbook {
|
|
862
|
-
export type Parameters = ReadParameters & Args
|
|
863
|
-
|
|
864
|
-
export type Args = {
|
|
865
|
-
/** Address of the base token. */
|
|
866
|
-
base: Address
|
|
867
|
-
/** Address of the quote token. */
|
|
868
|
-
quote: Address
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
export type ReturnValue = ReadContractReturnType<
|
|
872
|
-
typeof Abis.stablecoinExchange,
|
|
873
|
-
'books',
|
|
874
|
-
never
|
|
875
|
-
>
|
|
876
|
-
|
|
877
|
-
/**
|
|
878
|
-
* Defines a call to the `books` function.
|
|
879
|
-
*
|
|
880
|
-
* @param args - Arguments.
|
|
881
|
-
* @returns The call.
|
|
882
|
-
*/
|
|
883
|
-
export function call(args: Args) {
|
|
884
|
-
const { base, quote } = args
|
|
885
|
-
const pairKey = getPairKey(base, quote)
|
|
886
|
-
return defineCall({
|
|
887
|
-
address: Addresses.stablecoinExchange,
|
|
888
|
-
abi: Abis.stablecoinExchange,
|
|
889
|
-
args: [pairKey],
|
|
890
|
-
functionName: 'books',
|
|
891
|
-
})
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
/**
|
|
896
|
-
* Gets the price level information at a specific tick.
|
|
897
|
-
*
|
|
898
|
-
* @example
|
|
899
|
-
* ```ts
|
|
900
|
-
* import { createClient, http } from 'viem'
|
|
901
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
902
|
-
* import { Actions, Tick } from 'tempo.ts/viem'
|
|
903
|
-
*
|
|
904
|
-
* const client = createClient({
|
|
905
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
906
|
-
* transport: http(),
|
|
907
|
-
* })
|
|
908
|
-
*
|
|
909
|
-
* const level = await Actions.dex.getTickLevel(client, {
|
|
910
|
-
* base: '0x20c...11',
|
|
911
|
-
* tick: Tick.fromPrice('1.001'),
|
|
912
|
-
* isBid: true,
|
|
913
|
-
* })
|
|
914
|
-
* ```
|
|
915
|
-
*
|
|
916
|
-
* @param client - Client.
|
|
917
|
-
* @param parameters - Parameters.
|
|
918
|
-
* @returns The price level information.
|
|
919
|
-
*/
|
|
920
|
-
export async function getTickLevel<chain extends Chain | undefined>(
|
|
921
|
-
client: Client<Transport, chain>,
|
|
922
|
-
parameters: getTickLevel.Parameters,
|
|
923
|
-
): Promise<getTickLevel.ReturnValue> {
|
|
924
|
-
const { base, tick, isBid, ...rest } = parameters
|
|
925
|
-
const [head, tail, totalLiquidity] = await readContract(client, {
|
|
926
|
-
...rest,
|
|
927
|
-
...getTickLevel.call({ base, tick, isBid }),
|
|
928
|
-
})
|
|
929
|
-
return { head, tail, totalLiquidity }
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
export namespace getTickLevel {
|
|
933
|
-
export type Parameters = ReadParameters & Args
|
|
934
|
-
|
|
935
|
-
export type Args = {
|
|
936
|
-
/** Address of the base token. */
|
|
937
|
-
base: Address
|
|
938
|
-
/** Whether to query the bid side (true) or ask side (false). */
|
|
939
|
-
isBid: boolean
|
|
940
|
-
/** Price tick to query. */
|
|
941
|
-
tick: number
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
export type ReturnValue = {
|
|
945
|
-
/** Order ID of the first order at this tick (0 if empty) */
|
|
946
|
-
head: bigint
|
|
947
|
-
/** Order ID of the last order at this tick (0 if empty) */
|
|
948
|
-
tail: bigint
|
|
949
|
-
/** Total liquidity available at this tick level */
|
|
950
|
-
totalLiquidity: bigint
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
/**
|
|
954
|
-
* Defines a call to the `getTickLevel` function.
|
|
955
|
-
*
|
|
956
|
-
* @param args - Arguments.
|
|
957
|
-
* @returns The call.
|
|
958
|
-
*/
|
|
959
|
-
export function call(args: Args) {
|
|
960
|
-
const { base, tick, isBid } = args
|
|
961
|
-
return defineCall({
|
|
962
|
-
address: Addresses.stablecoinExchange,
|
|
963
|
-
abi: Abis.stablecoinExchange,
|
|
964
|
-
args: [base, tick, isBid],
|
|
965
|
-
functionName: 'getTickLevel',
|
|
966
|
-
})
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* Gets the quote for selling a specific amount of tokens.
|
|
972
|
-
*
|
|
973
|
-
* @example
|
|
974
|
-
* ```ts
|
|
975
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
976
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
977
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
978
|
-
*
|
|
979
|
-
* const client = createClient({
|
|
980
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
981
|
-
* transport: http(),
|
|
982
|
-
* })
|
|
983
|
-
*
|
|
984
|
-
* const amountOut = await Actions.dex.getSellQuote(client, {
|
|
985
|
-
* amountIn: parseUnits('100', 6),
|
|
986
|
-
* tokenIn: '0x20c...11',
|
|
987
|
-
* tokenOut: '0x20c...20',
|
|
988
|
-
* })
|
|
989
|
-
* ```
|
|
990
|
-
*
|
|
991
|
-
* @param client - Client.
|
|
992
|
-
* @param parameters - Parameters.
|
|
993
|
-
* @returns The amount of tokenOut received for selling the specified amountIn.
|
|
994
|
-
*/
|
|
995
|
-
export async function getSellQuote<chain extends Chain | undefined>(
|
|
996
|
-
client: Client<Transport, chain>,
|
|
997
|
-
parameters: getSellQuote.Parameters,
|
|
998
|
-
): Promise<getSellQuote.ReturnValue> {
|
|
999
|
-
const { tokenIn, tokenOut, amountIn, ...rest } = parameters
|
|
1000
|
-
return readContract(client, {
|
|
1001
|
-
...rest,
|
|
1002
|
-
...getSellQuote.call({ tokenIn, tokenOut, amountIn }),
|
|
1003
|
-
})
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
export namespace getSellQuote {
|
|
1007
|
-
export type Parameters = ReadParameters & Args
|
|
1008
|
-
|
|
1009
|
-
export type Args = {
|
|
1010
|
-
/** Amount of tokenIn to sell. */
|
|
1011
|
-
amountIn: bigint
|
|
1012
|
-
/** Address of the token to sell. */
|
|
1013
|
-
tokenIn: Address
|
|
1014
|
-
/** Address of the token to receive. */
|
|
1015
|
-
tokenOut: Address
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
export type ReturnValue = ReadContractReturnType<
|
|
1019
|
-
typeof Abis.stablecoinExchange,
|
|
1020
|
-
'quoteSwapExactAmountIn',
|
|
1021
|
-
never
|
|
1022
|
-
>
|
|
1023
|
-
|
|
1024
|
-
/**
|
|
1025
|
-
* Defines a call to the `quoteSwapExactAmountIn` function.
|
|
1026
|
-
*
|
|
1027
|
-
* @param args - Arguments.
|
|
1028
|
-
* @returns The call.
|
|
1029
|
-
*/
|
|
1030
|
-
export function call(args: Args) {
|
|
1031
|
-
const { tokenIn, tokenOut, amountIn } = args
|
|
1032
|
-
return defineCall({
|
|
1033
|
-
address: Addresses.stablecoinExchange,
|
|
1034
|
-
abi: Abis.stablecoinExchange,
|
|
1035
|
-
args: [tokenIn, tokenOut, amountIn],
|
|
1036
|
-
functionName: 'quoteSwapExactAmountIn',
|
|
1037
|
-
})
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
/**
|
|
1042
|
-
* Places a limit order on the orderbook.
|
|
1043
|
-
*
|
|
1044
|
-
* @example
|
|
1045
|
-
* ```ts
|
|
1046
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
1047
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1048
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1049
|
-
* import { Actions, Tick } from 'tempo.ts/viem'
|
|
1050
|
-
*
|
|
1051
|
-
* const client = createClient({
|
|
1052
|
-
* account: privateKeyToAccount('0x...'),
|
|
1053
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1054
|
-
* transport: http(),
|
|
1055
|
-
* })
|
|
1056
|
-
*
|
|
1057
|
-
* const hash = await Actions.dex.place(client, {
|
|
1058
|
-
* amount: parseUnits('100', 6),
|
|
1059
|
-
* tick: Tick.fromPrice('0.99'),
|
|
1060
|
-
* token: '0x20c...11',
|
|
1061
|
-
* type: 'buy',
|
|
1062
|
-
* })
|
|
1063
|
-
* ```
|
|
1064
|
-
*
|
|
1065
|
-
* @param client - Client.
|
|
1066
|
-
* @param parameters - Parameters.
|
|
1067
|
-
* @returns The transaction hash.
|
|
1068
|
-
*/
|
|
1069
|
-
export async function place<
|
|
1070
|
-
chain extends Chain | undefined,
|
|
1071
|
-
account extends Account | undefined,
|
|
1072
|
-
>(
|
|
1073
|
-
client: Client<Transport, chain, account>,
|
|
1074
|
-
parameters: place.Parameters<chain, account>,
|
|
1075
|
-
): Promise<place.ReturnValue> {
|
|
1076
|
-
return place.inner(writeContract, client, parameters)
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
export namespace place {
|
|
1080
|
-
export type Parameters<
|
|
1081
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
1082
|
-
account extends Account | undefined = Account | undefined,
|
|
1083
|
-
> = WriteParameters<chain, account> & Args
|
|
1084
|
-
|
|
1085
|
-
export type Args = {
|
|
1086
|
-
/** Amount of tokens to place in the order. */
|
|
1087
|
-
amount: bigint
|
|
1088
|
-
/** Price tick for the order. */
|
|
1089
|
-
tick: number
|
|
1090
|
-
/** Address of the base token. */
|
|
1091
|
-
token: Address
|
|
1092
|
-
/** Order type - 'buy' to buy the token, 'sell' to sell it. */
|
|
1093
|
-
type: OrderType
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
export type ReturnValue = WriteContractReturnType
|
|
1097
|
-
|
|
1098
|
-
// TODO: exhaustive error type
|
|
1099
|
-
export type ErrorType = BaseErrorType
|
|
1100
|
-
|
|
1101
|
-
/** @internal */
|
|
1102
|
-
export async function inner<
|
|
1103
|
-
action extends typeof writeContract | typeof writeContractSync,
|
|
1104
|
-
chain extends Chain | undefined,
|
|
1105
|
-
account extends Account | undefined,
|
|
1106
|
-
>(
|
|
1107
|
-
action: action,
|
|
1108
|
-
client: Client<Transport, chain, account>,
|
|
1109
|
-
parameters: place.Parameters<chain, account>,
|
|
1110
|
-
): Promise<ReturnType<action>> {
|
|
1111
|
-
const { amount, token, type, tick, ...rest } = parameters
|
|
1112
|
-
const call = place.call({ amount, token, type, tick })
|
|
1113
|
-
return (await action(client, {
|
|
1114
|
-
...rest,
|
|
1115
|
-
...call,
|
|
1116
|
-
} as never)) as never
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
/**
|
|
1120
|
-
* Defines a call to the `place` function.
|
|
1121
|
-
*
|
|
1122
|
-
* Can be passed as a parameter to:
|
|
1123
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1124
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1125
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1126
|
-
*
|
|
1127
|
-
* @example
|
|
1128
|
-
* ```ts
|
|
1129
|
-
* import { createClient, http, parseUnits, walletActions } from 'viem'
|
|
1130
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1131
|
-
* import { Actions, Tick } from 'tempo.ts/viem'
|
|
1132
|
-
*
|
|
1133
|
-
* const client = createClient({
|
|
1134
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1135
|
-
* transport: http(),
|
|
1136
|
-
* }).extend(walletActions)
|
|
1137
|
-
*
|
|
1138
|
-
* const { result } = await client.sendCalls({
|
|
1139
|
-
* calls: [
|
|
1140
|
-
* Actions.dex.place.call({
|
|
1141
|
-
* amount: parseUnits('100', 6),
|
|
1142
|
-
* tick: Tick.fromPrice('0.99'),
|
|
1143
|
-
* token: '0x20c0...beef',
|
|
1144
|
-
* type: 'buy',
|
|
1145
|
-
* }),
|
|
1146
|
-
* ]
|
|
1147
|
-
* })
|
|
1148
|
-
* ```
|
|
1149
|
-
*
|
|
1150
|
-
* @param args - Arguments.
|
|
1151
|
-
* @returns The call.
|
|
1152
|
-
*/
|
|
1153
|
-
export function call(args: Args) {
|
|
1154
|
-
const { token, amount, type, tick } = args
|
|
1155
|
-
const isBid = type === 'buy'
|
|
1156
|
-
return defineCall({
|
|
1157
|
-
address: Addresses.stablecoinExchange,
|
|
1158
|
-
abi: Abis.stablecoinExchange,
|
|
1159
|
-
functionName: 'place',
|
|
1160
|
-
args: [token, amount, isBid, tick],
|
|
1161
|
-
})
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
/**
|
|
1165
|
-
* Extracts the `OrderPlaced` event from logs.
|
|
1166
|
-
*
|
|
1167
|
-
* @param logs - The logs.
|
|
1168
|
-
* @returns The `OrderPlaced` event.
|
|
1169
|
-
*/
|
|
1170
|
-
export function extractEvent(logs: Log[]) {
|
|
1171
|
-
const [log] = parseEventLogs({
|
|
1172
|
-
abi: Abis.stablecoinExchange,
|
|
1173
|
-
logs,
|
|
1174
|
-
eventName: 'OrderPlaced',
|
|
1175
|
-
strict: true,
|
|
1176
|
-
})
|
|
1177
|
-
if (!log) throw new Error('`OrderPlaced` event not found.')
|
|
1178
|
-
return log
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
/**
|
|
1183
|
-
* Places a flip order that automatically flips when filled.
|
|
1184
|
-
*
|
|
1185
|
-
* @example
|
|
1186
|
-
* ```ts
|
|
1187
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
1188
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1189
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1190
|
-
* import { Actions, Tick } from 'tempo.ts/viem'
|
|
1191
|
-
*
|
|
1192
|
-
* const client = createClient({
|
|
1193
|
-
* account: privateKeyToAccount('0x...'),
|
|
1194
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1195
|
-
* transport: http(),
|
|
1196
|
-
* })
|
|
1197
|
-
*
|
|
1198
|
-
* const hash = await Actions.dex.placeFlip(client, {
|
|
1199
|
-
* amount: parseUnits('100', 6),
|
|
1200
|
-
* flipTick: Tick.fromPrice('1.01'),
|
|
1201
|
-
* tick: Tick.fromPrice('0.99'),
|
|
1202
|
-
* token: '0x20c...11',
|
|
1203
|
-
* type: 'buy',
|
|
1204
|
-
* })
|
|
1205
|
-
* ```
|
|
1206
|
-
*
|
|
1207
|
-
* @param client - Client.
|
|
1208
|
-
* @param parameters - Parameters.
|
|
1209
|
-
* @returns The transaction hash.
|
|
1210
|
-
*/
|
|
1211
|
-
export async function placeFlip<
|
|
1212
|
-
chain extends Chain | undefined,
|
|
1213
|
-
account extends Account | undefined,
|
|
1214
|
-
>(
|
|
1215
|
-
client: Client<Transport, chain, account>,
|
|
1216
|
-
parameters: placeFlip.Parameters<chain, account>,
|
|
1217
|
-
): Promise<placeFlip.ReturnValue> {
|
|
1218
|
-
return placeFlip.inner(writeContract, client, parameters)
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
export namespace placeFlip {
|
|
1222
|
-
export type Parameters<
|
|
1223
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
1224
|
-
account extends Account | undefined = Account | undefined,
|
|
1225
|
-
> = WriteParameters<chain, account> & Args
|
|
1226
|
-
|
|
1227
|
-
export type Args = {
|
|
1228
|
-
/** Amount of tokens to place in the order. */
|
|
1229
|
-
amount: bigint
|
|
1230
|
-
/** Target tick to flip to when order is filled. */
|
|
1231
|
-
flipTick: number
|
|
1232
|
-
/** Price tick for the order. */
|
|
1233
|
-
tick: number
|
|
1234
|
-
/** Address of the base token. */
|
|
1235
|
-
token: Address
|
|
1236
|
-
/** Order type - 'buy' to buy the token, 'sell' to sell it. */
|
|
1237
|
-
type: OrderType
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
export type ReturnValue = WriteContractReturnType
|
|
1241
|
-
|
|
1242
|
-
// TODO: exhaustive error type
|
|
1243
|
-
export type ErrorType = BaseErrorType
|
|
1244
|
-
|
|
1245
|
-
/** @internal */
|
|
1246
|
-
export async function inner<
|
|
1247
|
-
action extends typeof writeContract | typeof writeContractSync,
|
|
1248
|
-
chain extends Chain | undefined,
|
|
1249
|
-
account extends Account | undefined,
|
|
1250
|
-
>(
|
|
1251
|
-
action: action,
|
|
1252
|
-
client: Client<Transport, chain, account>,
|
|
1253
|
-
parameters: placeFlip.Parameters<chain, account>,
|
|
1254
|
-
): Promise<ReturnType<action>> {
|
|
1255
|
-
const { amount, flipTick, tick, token, type, ...rest } = parameters
|
|
1256
|
-
const call = placeFlip.call({ amount, flipTick, tick, token, type })
|
|
1257
|
-
return (await action(client, {
|
|
1258
|
-
...rest,
|
|
1259
|
-
...call,
|
|
1260
|
-
} as never)) as never
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
/**
|
|
1264
|
-
* Defines a call to the `placeFlip` function.
|
|
1265
|
-
*
|
|
1266
|
-
* Can be passed as a parameter to:
|
|
1267
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1268
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1269
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1270
|
-
*
|
|
1271
|
-
* @example
|
|
1272
|
-
* ```ts
|
|
1273
|
-
* import { createClient, http, parseUnits, walletActions } from 'viem'
|
|
1274
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1275
|
-
* import { Actions, Tick } from 'tempo.ts/viem'
|
|
1276
|
-
*
|
|
1277
|
-
* const client = createClient({
|
|
1278
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1279
|
-
* transport: http(),
|
|
1280
|
-
* }).extend(walletActions)
|
|
1281
|
-
*
|
|
1282
|
-
* const { result } = await client.sendCalls({
|
|
1283
|
-
* calls: [
|
|
1284
|
-
* Actions.dex.placeFlip.call({
|
|
1285
|
-
* amount: parseUnits('100', 6),
|
|
1286
|
-
* flipTick: Tick.fromPrice('1.01'),
|
|
1287
|
-
* tick: Tick.fromPrice('0.99'),
|
|
1288
|
-
* token: '0x20c0...beef',
|
|
1289
|
-
* type: 'buy',
|
|
1290
|
-
* }),
|
|
1291
|
-
* ]
|
|
1292
|
-
* })
|
|
1293
|
-
* ```
|
|
1294
|
-
*
|
|
1295
|
-
* @param args - Arguments.
|
|
1296
|
-
* @returns The call.
|
|
1297
|
-
*/
|
|
1298
|
-
export function call(args: Args) {
|
|
1299
|
-
const { token, amount, type, tick, flipTick } = args
|
|
1300
|
-
const isBid = type === 'buy'
|
|
1301
|
-
return defineCall({
|
|
1302
|
-
address: Addresses.stablecoinExchange,
|
|
1303
|
-
abi: Abis.stablecoinExchange,
|
|
1304
|
-
functionName: 'placeFlip',
|
|
1305
|
-
args: [token, amount, isBid, tick, flipTick],
|
|
1306
|
-
})
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
/**
|
|
1310
|
-
* Extracts the `FlipOrderPlaced` event from logs.
|
|
1311
|
-
*
|
|
1312
|
-
* @param logs - The logs.
|
|
1313
|
-
* @returns The `FlipOrderPlaced` event.
|
|
1314
|
-
*/
|
|
1315
|
-
export function extractEvent(logs: Log[]) {
|
|
1316
|
-
const [log] = parseEventLogs({
|
|
1317
|
-
abi: Abis.stablecoinExchange,
|
|
1318
|
-
logs,
|
|
1319
|
-
eventName: 'FlipOrderPlaced',
|
|
1320
|
-
strict: true,
|
|
1321
|
-
})
|
|
1322
|
-
if (!log) throw new Error('`FlipOrderPlaced` event not found.')
|
|
1323
|
-
return log
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
/**
|
|
1328
|
-
* Places a flip order that automatically flips when filled.
|
|
1329
|
-
*
|
|
1330
|
-
* @example
|
|
1331
|
-
* ```ts
|
|
1332
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
1333
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1334
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1335
|
-
* import { Actions, Tick } from 'tempo.ts/viem'
|
|
1336
|
-
*
|
|
1337
|
-
* const client = createClient({
|
|
1338
|
-
* account: privateKeyToAccount('0x...'),
|
|
1339
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1340
|
-
* transport: http(),
|
|
1341
|
-
* })
|
|
1342
|
-
*
|
|
1343
|
-
* const result = await Actions.dex.placeFlipSync(client, {
|
|
1344
|
-
* amount: parseUnits('100', 6),
|
|
1345
|
-
* flipTick: Tick.fromPrice('1.01'),
|
|
1346
|
-
* tick: Tick.fromPrice('0.99'),
|
|
1347
|
-
* token: '0x20c...11',
|
|
1348
|
-
* type: 'buy',
|
|
1349
|
-
* })
|
|
1350
|
-
* ```
|
|
1351
|
-
*
|
|
1352
|
-
* @param client - Client.
|
|
1353
|
-
* @param parameters - Parameters.
|
|
1354
|
-
* @returns The transaction receipt and event data.
|
|
1355
|
-
*/
|
|
1356
|
-
export async function placeFlipSync<
|
|
1357
|
-
chain extends Chain | undefined,
|
|
1358
|
-
account extends Account | undefined,
|
|
1359
|
-
>(
|
|
1360
|
-
client: Client<Transport, chain, account>,
|
|
1361
|
-
parameters: placeFlipSync.Parameters<chain, account>,
|
|
1362
|
-
): Promise<placeFlipSync.ReturnValue> {
|
|
1363
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
1364
|
-
const receipt = await placeFlip.inner(writeContractSync, client, {
|
|
1365
|
-
...rest,
|
|
1366
|
-
throwOnReceiptRevert,
|
|
1367
|
-
} as never)
|
|
1368
|
-
const { args } = placeFlip.extractEvent(receipt.logs)
|
|
1369
|
-
return {
|
|
1370
|
-
...args,
|
|
1371
|
-
receipt,
|
|
1372
|
-
} as never
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
export namespace placeFlipSync {
|
|
1376
|
-
export type Parameters<
|
|
1377
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
1378
|
-
account extends Account | undefined = Account | undefined,
|
|
1379
|
-
> = placeFlip.Parameters<chain, account>
|
|
1380
|
-
|
|
1381
|
-
export type Args = placeFlip.Args
|
|
1382
|
-
|
|
1383
|
-
export type ReturnValue = Compute<
|
|
1384
|
-
GetEventArgs<
|
|
1385
|
-
typeof Abis.stablecoinExchange,
|
|
1386
|
-
'FlipOrderPlaced',
|
|
1387
|
-
{ IndexedOnly: false; Required: true }
|
|
1388
|
-
> & {
|
|
1389
|
-
/** Transaction receipt. */
|
|
1390
|
-
receipt: TransactionReceipt
|
|
1391
|
-
}
|
|
1392
|
-
>
|
|
1393
|
-
|
|
1394
|
-
// TODO: exhaustive error type
|
|
1395
|
-
export type ErrorType = BaseErrorType
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
/**
|
|
1399
|
-
* Places a limit order on the orderbook.
|
|
1400
|
-
*
|
|
1401
|
-
* @example
|
|
1402
|
-
* ```ts
|
|
1403
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
1404
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1405
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1406
|
-
* import { Actions, Tick } from 'tempo.ts/viem'
|
|
1407
|
-
*
|
|
1408
|
-
* const client = createClient({
|
|
1409
|
-
* account: privateKeyToAccount('0x...'),
|
|
1410
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1411
|
-
* transport: http(),
|
|
1412
|
-
* })
|
|
1413
|
-
*
|
|
1414
|
-
* const result = await Actions.dex.placeSync(client, {
|
|
1415
|
-
* amount: parseUnits('100', 6),
|
|
1416
|
-
* tick: Tick.fromPrice('0.99'),
|
|
1417
|
-
* token: '0x20c...11',
|
|
1418
|
-
* type: 'buy',
|
|
1419
|
-
* })
|
|
1420
|
-
* ```
|
|
1421
|
-
*
|
|
1422
|
-
* @param client - Client.
|
|
1423
|
-
* @param parameters - Parameters.
|
|
1424
|
-
* @returns The transaction receipt and event data.
|
|
1425
|
-
*/
|
|
1426
|
-
export async function placeSync<
|
|
1427
|
-
chain extends Chain | undefined,
|
|
1428
|
-
account extends Account | undefined,
|
|
1429
|
-
>(
|
|
1430
|
-
client: Client<Transport, chain, account>,
|
|
1431
|
-
parameters: placeSync.Parameters<chain, account>,
|
|
1432
|
-
): Promise<placeSync.ReturnValue> {
|
|
1433
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
1434
|
-
const receipt = await place.inner(writeContractSync, client, {
|
|
1435
|
-
...rest,
|
|
1436
|
-
throwOnReceiptRevert,
|
|
1437
|
-
} as never)
|
|
1438
|
-
const { args } = place.extractEvent(receipt.logs)
|
|
1439
|
-
return {
|
|
1440
|
-
...args,
|
|
1441
|
-
receipt,
|
|
1442
|
-
} as never
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
export namespace placeSync {
|
|
1446
|
-
export type Parameters<
|
|
1447
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
1448
|
-
account extends Account | undefined = Account | undefined,
|
|
1449
|
-
> = place.Parameters<chain, account>
|
|
1450
|
-
|
|
1451
|
-
export type Args = place.Args
|
|
1452
|
-
|
|
1453
|
-
export type ReturnValue = Compute<
|
|
1454
|
-
GetEventArgs<
|
|
1455
|
-
typeof Abis.stablecoinExchange,
|
|
1456
|
-
'OrderPlaced',
|
|
1457
|
-
{ IndexedOnly: false; Required: true }
|
|
1458
|
-
> & {
|
|
1459
|
-
/** Transaction receipt. */
|
|
1460
|
-
receipt: TransactionReceipt
|
|
1461
|
-
}
|
|
1462
|
-
>
|
|
1463
|
-
|
|
1464
|
-
// TODO: exhaustive error type
|
|
1465
|
-
export type ErrorType = BaseErrorType
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
/**
|
|
1469
|
-
* Sells a specific amount of tokens.
|
|
1470
|
-
*
|
|
1471
|
-
* @example
|
|
1472
|
-
* ```ts
|
|
1473
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
1474
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1475
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1476
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1477
|
-
*
|
|
1478
|
-
* const client = createClient({
|
|
1479
|
-
* account: privateKeyToAccount('0x...'),
|
|
1480
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1481
|
-
* transport: http(),
|
|
1482
|
-
* })
|
|
1483
|
-
*
|
|
1484
|
-
* const hash = await Actions.dex.sell(client, {
|
|
1485
|
-
* amountIn: parseUnits('100', 6),
|
|
1486
|
-
* minAmountOut: parseUnits('95', 6),
|
|
1487
|
-
* tokenIn: '0x20c...11',
|
|
1488
|
-
* tokenOut: '0x20c...20',
|
|
1489
|
-
* })
|
|
1490
|
-
* ```
|
|
1491
|
-
*
|
|
1492
|
-
* @param client - Client.
|
|
1493
|
-
* @param parameters - Parameters.
|
|
1494
|
-
* @returns The transaction hash.
|
|
1495
|
-
*/
|
|
1496
|
-
export async function sell<
|
|
1497
|
-
chain extends Chain | undefined,
|
|
1498
|
-
account extends Account | undefined,
|
|
1499
|
-
>(
|
|
1500
|
-
client: Client<Transport, chain, account>,
|
|
1501
|
-
parameters: sell.Parameters<chain, account>,
|
|
1502
|
-
): Promise<sell.ReturnValue> {
|
|
1503
|
-
return sell.inner(writeContract, client, parameters)
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
export namespace sell {
|
|
1507
|
-
export type Parameters<
|
|
1508
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
1509
|
-
account extends Account | undefined = Account | undefined,
|
|
1510
|
-
> = WriteParameters<chain, account> & Args
|
|
1511
|
-
|
|
1512
|
-
export type Args = {
|
|
1513
|
-
/** Amount of tokenIn to sell. */
|
|
1514
|
-
amountIn: bigint
|
|
1515
|
-
/** Minimum amount of tokenOut to receive. */
|
|
1516
|
-
minAmountOut: bigint
|
|
1517
|
-
/** Address of the token to sell. */
|
|
1518
|
-
tokenIn: Address
|
|
1519
|
-
/** Address of the token to receive. */
|
|
1520
|
-
tokenOut: Address
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
export type ReturnValue = WriteContractReturnType
|
|
1524
|
-
|
|
1525
|
-
// TODO: exhaustive error type
|
|
1526
|
-
export type ErrorType = BaseErrorType
|
|
1527
|
-
|
|
1528
|
-
/** @internal */
|
|
1529
|
-
export async function inner<
|
|
1530
|
-
action extends typeof writeContract | typeof writeContractSync,
|
|
1531
|
-
chain extends Chain | undefined,
|
|
1532
|
-
account extends Account | undefined,
|
|
1533
|
-
>(
|
|
1534
|
-
action: action,
|
|
1535
|
-
client: Client<Transport, chain, account>,
|
|
1536
|
-
parameters: sell.Parameters<chain, account>,
|
|
1537
|
-
): Promise<ReturnType<action>> {
|
|
1538
|
-
const { tokenIn, tokenOut, amountIn, minAmountOut, ...rest } = parameters
|
|
1539
|
-
const call = sell.call({ tokenIn, tokenOut, amountIn, minAmountOut })
|
|
1540
|
-
return (await action(client, {
|
|
1541
|
-
...rest,
|
|
1542
|
-
...call,
|
|
1543
|
-
} as never)) as never
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
/**
|
|
1547
|
-
* Defines a call to the `swapExactAmountIn` function.
|
|
1548
|
-
*
|
|
1549
|
-
* Can be passed as a parameter to:
|
|
1550
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1551
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1552
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1553
|
-
*
|
|
1554
|
-
* @example
|
|
1555
|
-
* ```ts
|
|
1556
|
-
* import { createClient, http, parseUnits, walletActions } from 'viem'
|
|
1557
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1558
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1559
|
-
*
|
|
1560
|
-
* const client = createClient({
|
|
1561
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1562
|
-
* transport: http(),
|
|
1563
|
-
* }).extend(walletActions)
|
|
1564
|
-
*
|
|
1565
|
-
* const { result } = await client.sendCalls({
|
|
1566
|
-
* calls: [
|
|
1567
|
-
* Actions.dex.sell.call({
|
|
1568
|
-
* amountIn: parseUnits('100', 6),
|
|
1569
|
-
* minAmountOut: parseUnits('95', 6),
|
|
1570
|
-
* tokenIn: '0x20c0...beef',
|
|
1571
|
-
* tokenOut: '0x20c0...babe',
|
|
1572
|
-
* }),
|
|
1573
|
-
* ]
|
|
1574
|
-
* })
|
|
1575
|
-
* ```
|
|
1576
|
-
*
|
|
1577
|
-
* @param args - Arguments.
|
|
1578
|
-
* @returns The call.
|
|
1579
|
-
*/
|
|
1580
|
-
export function call(args: Args) {
|
|
1581
|
-
const { tokenIn, tokenOut, amountIn, minAmountOut } = args
|
|
1582
|
-
return defineCall({
|
|
1583
|
-
address: Addresses.stablecoinExchange,
|
|
1584
|
-
abi: Abis.stablecoinExchange,
|
|
1585
|
-
functionName: 'swapExactAmountIn',
|
|
1586
|
-
args: [tokenIn, tokenOut, amountIn, minAmountOut],
|
|
1587
|
-
})
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
/**
|
|
1592
|
-
* Sells a specific amount of tokens.
|
|
1593
|
-
*
|
|
1594
|
-
* @example
|
|
1595
|
-
* ```ts
|
|
1596
|
-
* import { createClient, http, parseUnits } from 'viem'
|
|
1597
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1598
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1599
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1600
|
-
*
|
|
1601
|
-
* const client = createClient({
|
|
1602
|
-
* account: privateKeyToAccount('0x...'),
|
|
1603
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1604
|
-
* transport: http(),
|
|
1605
|
-
* })
|
|
1606
|
-
*
|
|
1607
|
-
* const result = await Actions.dex.sellSync(client, {
|
|
1608
|
-
* amountIn: parseUnits('100', 6),
|
|
1609
|
-
* minAmountOut: parseUnits('95', 6),
|
|
1610
|
-
* tokenIn: '0x20c...11',
|
|
1611
|
-
* tokenOut: '0x20c...20',
|
|
1612
|
-
* })
|
|
1613
|
-
* ```
|
|
1614
|
-
*
|
|
1615
|
-
* @param client - Client.
|
|
1616
|
-
* @param parameters - Parameters.
|
|
1617
|
-
* @returns The transaction receipt.
|
|
1618
|
-
*/
|
|
1619
|
-
export async function sellSync<
|
|
1620
|
-
chain extends Chain | undefined,
|
|
1621
|
-
account extends Account | undefined,
|
|
1622
|
-
>(
|
|
1623
|
-
client: Client<Transport, chain, account>,
|
|
1624
|
-
parameters: sellSync.Parameters<chain, account>,
|
|
1625
|
-
): Promise<sellSync.ReturnValue> {
|
|
1626
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
1627
|
-
const receipt = await sell.inner(writeContractSync, client, {
|
|
1628
|
-
...rest,
|
|
1629
|
-
throwOnReceiptRevert,
|
|
1630
|
-
} as never)
|
|
1631
|
-
return { receipt }
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
export namespace sellSync {
|
|
1635
|
-
export type Parameters<
|
|
1636
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
1637
|
-
account extends Account | undefined = Account | undefined,
|
|
1638
|
-
> = sell.Parameters<chain, account>
|
|
1639
|
-
|
|
1640
|
-
export type Args = sell.Args
|
|
1641
|
-
|
|
1642
|
-
export type ReturnValue = Compute<{
|
|
1643
|
-
/** Transaction receipt. */
|
|
1644
|
-
receipt: TransactionReceipt
|
|
1645
|
-
}>
|
|
1646
|
-
|
|
1647
|
-
// TODO: exhaustive error type
|
|
1648
|
-
export type ErrorType = BaseErrorType
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
|
-
/**
|
|
1652
|
-
* Watches for flip order placed events.
|
|
1653
|
-
*
|
|
1654
|
-
* @example
|
|
1655
|
-
* ```ts
|
|
1656
|
-
* import { createClient, http } from 'viem'
|
|
1657
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1658
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1659
|
-
*
|
|
1660
|
-
* const client = createClient({
|
|
1661
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1662
|
-
* transport: http(),
|
|
1663
|
-
* })
|
|
1664
|
-
*
|
|
1665
|
-
* const unwatch = Actions.dex.watchFlipOrderPlaced(client, {
|
|
1666
|
-
* onFlipOrderPlaced: (args, log) => {
|
|
1667
|
-
* console.log('Flip order placed:', args)
|
|
1668
|
-
* },
|
|
1669
|
-
* })
|
|
1670
|
-
* ```
|
|
1671
|
-
*
|
|
1672
|
-
* @param client - Client.
|
|
1673
|
-
* @param parameters - Parameters.
|
|
1674
|
-
* @returns A function to unsubscribe from the event.
|
|
1675
|
-
*/
|
|
1676
|
-
export function watchFlipOrderPlaced<
|
|
1677
|
-
chain extends Chain | undefined,
|
|
1678
|
-
account extends Account | undefined,
|
|
1679
|
-
>(
|
|
1680
|
-
client: Client<Transport, chain, account>,
|
|
1681
|
-
parameters: watchFlipOrderPlaced.Parameters,
|
|
1682
|
-
) {
|
|
1683
|
-
const { onFlipOrderPlaced, maker, token, ...rest } = parameters
|
|
1684
|
-
return watchContractEvent(client, {
|
|
1685
|
-
...rest,
|
|
1686
|
-
address: Addresses.stablecoinExchange,
|
|
1687
|
-
abi: Abis.stablecoinExchange,
|
|
1688
|
-
eventName: 'FlipOrderPlaced',
|
|
1689
|
-
args: {
|
|
1690
|
-
...(maker !== undefined && { maker }),
|
|
1691
|
-
...(token !== undefined && { token }),
|
|
1692
|
-
},
|
|
1693
|
-
onLogs: (logs) => {
|
|
1694
|
-
for (const log of logs) onFlipOrderPlaced(log.args, log)
|
|
1695
|
-
},
|
|
1696
|
-
strict: true,
|
|
1697
|
-
})
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
export declare namespace watchFlipOrderPlaced {
|
|
1701
|
-
export type Args = GetEventArgs<
|
|
1702
|
-
typeof Abis.stablecoinExchange,
|
|
1703
|
-
'FlipOrderPlaced',
|
|
1704
|
-
{ IndexedOnly: false; Required: true }
|
|
1705
|
-
>
|
|
1706
|
-
|
|
1707
|
-
export type Log = viem_Log<
|
|
1708
|
-
bigint,
|
|
1709
|
-
number,
|
|
1710
|
-
false,
|
|
1711
|
-
ExtractAbiItem<typeof Abis.stablecoinExchange, 'FlipOrderPlaced'>,
|
|
1712
|
-
true
|
|
1713
|
-
>
|
|
1714
|
-
|
|
1715
|
-
export type Parameters = UnionOmit<
|
|
1716
|
-
WatchContractEventParameters<
|
|
1717
|
-
typeof Abis.stablecoinExchange,
|
|
1718
|
-
'FlipOrderPlaced',
|
|
1719
|
-
true
|
|
1720
|
-
>,
|
|
1721
|
-
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1722
|
-
> & {
|
|
1723
|
-
/** Address of the maker to filter events. */
|
|
1724
|
-
maker?: Address | undefined
|
|
1725
|
-
/** Callback to invoke when a flip order is placed. */
|
|
1726
|
-
onFlipOrderPlaced: (args: Args, log: Log) => void
|
|
1727
|
-
/** Address of the token to filter events. */
|
|
1728
|
-
token?: Address | undefined
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
/**
|
|
1733
|
-
* Watches for order cancelled events.
|
|
1734
|
-
*
|
|
1735
|
-
* @example
|
|
1736
|
-
* ```ts
|
|
1737
|
-
* import { createClient, http } from 'viem'
|
|
1738
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1739
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1740
|
-
*
|
|
1741
|
-
* const client = createClient({
|
|
1742
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1743
|
-
* transport: http(),
|
|
1744
|
-
* })
|
|
1745
|
-
*
|
|
1746
|
-
* const unwatch = Actions.dex.watchOrderCancelled(client, {
|
|
1747
|
-
* onOrderCancelled: (args, log) => {
|
|
1748
|
-
* console.log('Order cancelled:', args)
|
|
1749
|
-
* },
|
|
1750
|
-
* })
|
|
1751
|
-
* ```
|
|
1752
|
-
*
|
|
1753
|
-
* @param client - Client.
|
|
1754
|
-
* @param parameters - Parameters.
|
|
1755
|
-
* @returns A function to unsubscribe from the event.
|
|
1756
|
-
*/
|
|
1757
|
-
export function watchOrderCancelled<
|
|
1758
|
-
chain extends Chain | undefined,
|
|
1759
|
-
account extends Account | undefined,
|
|
1760
|
-
>(
|
|
1761
|
-
client: Client<Transport, chain, account>,
|
|
1762
|
-
parameters: watchOrderCancelled.Parameters,
|
|
1763
|
-
) {
|
|
1764
|
-
const { onOrderCancelled, orderId, ...rest } = parameters
|
|
1765
|
-
return watchContractEvent(client, {
|
|
1766
|
-
...rest,
|
|
1767
|
-
address: Addresses.stablecoinExchange,
|
|
1768
|
-
abi: Abis.stablecoinExchange,
|
|
1769
|
-
eventName: 'OrderCancelled',
|
|
1770
|
-
args: orderId !== undefined ? { orderId } : undefined,
|
|
1771
|
-
onLogs: (logs) => {
|
|
1772
|
-
for (const log of logs) onOrderCancelled(log.args, log)
|
|
1773
|
-
},
|
|
1774
|
-
strict: true,
|
|
1775
|
-
})
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
export declare namespace watchOrderCancelled {
|
|
1779
|
-
export type Args = GetEventArgs<
|
|
1780
|
-
typeof Abis.stablecoinExchange,
|
|
1781
|
-
'OrderCancelled',
|
|
1782
|
-
{ IndexedOnly: false; Required: true }
|
|
1783
|
-
>
|
|
1784
|
-
|
|
1785
|
-
export type Log = viem_Log<
|
|
1786
|
-
bigint,
|
|
1787
|
-
number,
|
|
1788
|
-
false,
|
|
1789
|
-
ExtractAbiItem<typeof Abis.stablecoinExchange, 'OrderCancelled'>,
|
|
1790
|
-
true
|
|
1791
|
-
>
|
|
1792
|
-
|
|
1793
|
-
export type Parameters = UnionOmit<
|
|
1794
|
-
WatchContractEventParameters<
|
|
1795
|
-
typeof Abis.stablecoinExchange,
|
|
1796
|
-
'OrderCancelled',
|
|
1797
|
-
true
|
|
1798
|
-
>,
|
|
1799
|
-
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1800
|
-
> & {
|
|
1801
|
-
/** Callback to invoke when an order is cancelled. */
|
|
1802
|
-
onOrderCancelled: (args: Args, log: Log) => void
|
|
1803
|
-
/** Order ID to filter events. */
|
|
1804
|
-
orderId?: bigint | undefined
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
/**
|
|
1809
|
-
* Watches for order filled events.
|
|
1810
|
-
*
|
|
1811
|
-
* @example
|
|
1812
|
-
* ```ts
|
|
1813
|
-
* import { createClient, http } from 'viem'
|
|
1814
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1815
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1816
|
-
*
|
|
1817
|
-
* const client = createClient({
|
|
1818
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1819
|
-
* transport: http(),
|
|
1820
|
-
* })
|
|
1821
|
-
*
|
|
1822
|
-
* const unwatch = Actions.dex.watchOrderFilled(client, {
|
|
1823
|
-
* onOrderFilled: (args, log) => {
|
|
1824
|
-
* console.log('Order filled:', args)
|
|
1825
|
-
* },
|
|
1826
|
-
* })
|
|
1827
|
-
* ```
|
|
1828
|
-
*
|
|
1829
|
-
* @param client - Client.
|
|
1830
|
-
* @param parameters - Parameters.
|
|
1831
|
-
* @returns A function to unsubscribe from the event.
|
|
1832
|
-
*/
|
|
1833
|
-
export function watchOrderFilled<
|
|
1834
|
-
chain extends Chain | undefined,
|
|
1835
|
-
account extends Account | undefined,
|
|
1836
|
-
>(
|
|
1837
|
-
client: Client<Transport, chain, account>,
|
|
1838
|
-
parameters: watchOrderFilled.Parameters,
|
|
1839
|
-
) {
|
|
1840
|
-
const { onOrderFilled, maker, taker, orderId, ...rest } = parameters
|
|
1841
|
-
return watchContractEvent(client, {
|
|
1842
|
-
...rest,
|
|
1843
|
-
address: Addresses.stablecoinExchange,
|
|
1844
|
-
abi: Abis.stablecoinExchange,
|
|
1845
|
-
eventName: 'OrderFilled',
|
|
1846
|
-
args: {
|
|
1847
|
-
...(orderId !== undefined && { orderId }),
|
|
1848
|
-
...(maker !== undefined && { maker }),
|
|
1849
|
-
...(taker !== undefined && { taker }),
|
|
1850
|
-
},
|
|
1851
|
-
onLogs: (logs) => {
|
|
1852
|
-
for (const log of logs) onOrderFilled(log.args, log)
|
|
1853
|
-
},
|
|
1854
|
-
strict: true,
|
|
1855
|
-
})
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
export declare namespace watchOrderFilled {
|
|
1859
|
-
export type Args = GetEventArgs<
|
|
1860
|
-
typeof Abis.stablecoinExchange,
|
|
1861
|
-
'OrderFilled',
|
|
1862
|
-
{ IndexedOnly: false; Required: true }
|
|
1863
|
-
>
|
|
1864
|
-
|
|
1865
|
-
export type Log = viem_Log<
|
|
1866
|
-
bigint,
|
|
1867
|
-
number,
|
|
1868
|
-
false,
|
|
1869
|
-
ExtractAbiItem<typeof Abis.stablecoinExchange, 'OrderFilled'>,
|
|
1870
|
-
true
|
|
1871
|
-
>
|
|
1872
|
-
|
|
1873
|
-
export type Parameters = UnionOmit<
|
|
1874
|
-
WatchContractEventParameters<
|
|
1875
|
-
typeof Abis.stablecoinExchange,
|
|
1876
|
-
'OrderFilled',
|
|
1877
|
-
true
|
|
1878
|
-
>,
|
|
1879
|
-
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1880
|
-
> & {
|
|
1881
|
-
/** Address of the maker to filter events. */
|
|
1882
|
-
maker?: Address | undefined
|
|
1883
|
-
/** Callback to invoke when an order is filled. */
|
|
1884
|
-
onOrderFilled: (args: Args, log: Log) => void
|
|
1885
|
-
/** Order ID to filter events. */
|
|
1886
|
-
orderId?: bigint | undefined
|
|
1887
|
-
/** Address of the taker to filter events. */
|
|
1888
|
-
taker?: Address | undefined
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
/**
|
|
1893
|
-
* Watches for order placed events.
|
|
1894
|
-
*
|
|
1895
|
-
* @example
|
|
1896
|
-
* ```ts
|
|
1897
|
-
* import { createClient, http } from 'viem'
|
|
1898
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1899
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1900
|
-
*
|
|
1901
|
-
* const client = createClient({
|
|
1902
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1903
|
-
* transport: http(),
|
|
1904
|
-
* })
|
|
1905
|
-
*
|
|
1906
|
-
* const unwatch = Actions.dex.watchOrderPlaced(client, {
|
|
1907
|
-
* onOrderPlaced: (args, log) => {
|
|
1908
|
-
* console.log('Order placed:', args)
|
|
1909
|
-
* },
|
|
1910
|
-
* })
|
|
1911
|
-
* ```
|
|
1912
|
-
*
|
|
1913
|
-
* @param client - Client.
|
|
1914
|
-
* @param parameters - Parameters.
|
|
1915
|
-
* @returns A function to unsubscribe from the event.
|
|
1916
|
-
*/
|
|
1917
|
-
export function watchOrderPlaced<
|
|
1918
|
-
chain extends Chain | undefined,
|
|
1919
|
-
account extends Account | undefined,
|
|
1920
|
-
>(
|
|
1921
|
-
client: Client<Transport, chain, account>,
|
|
1922
|
-
parameters: watchOrderPlaced.Parameters,
|
|
1923
|
-
) {
|
|
1924
|
-
const { onOrderPlaced, maker, token, ...rest } = parameters
|
|
1925
|
-
return watchContractEvent(client, {
|
|
1926
|
-
...rest,
|
|
1927
|
-
address: Addresses.stablecoinExchange,
|
|
1928
|
-
abi: Abis.stablecoinExchange,
|
|
1929
|
-
eventName: 'OrderPlaced',
|
|
1930
|
-
args: {
|
|
1931
|
-
...(maker !== undefined && { maker }),
|
|
1932
|
-
...(token !== undefined && { token }),
|
|
1933
|
-
},
|
|
1934
|
-
onLogs: (logs) => {
|
|
1935
|
-
for (const log of logs) onOrderPlaced(log.args, log)
|
|
1936
|
-
},
|
|
1937
|
-
strict: true,
|
|
1938
|
-
})
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
export declare namespace watchOrderPlaced {
|
|
1942
|
-
export type Args = GetEventArgs<
|
|
1943
|
-
typeof Abis.stablecoinExchange,
|
|
1944
|
-
'OrderPlaced',
|
|
1945
|
-
{ IndexedOnly: false; Required: true }
|
|
1946
|
-
>
|
|
1947
|
-
|
|
1948
|
-
export type Log = viem_Log<
|
|
1949
|
-
bigint,
|
|
1950
|
-
number,
|
|
1951
|
-
false,
|
|
1952
|
-
ExtractAbiItem<typeof Abis.stablecoinExchange, 'OrderPlaced'>,
|
|
1953
|
-
true
|
|
1954
|
-
>
|
|
1955
|
-
|
|
1956
|
-
export type Parameters = UnionOmit<
|
|
1957
|
-
WatchContractEventParameters<
|
|
1958
|
-
typeof Abis.stablecoinExchange,
|
|
1959
|
-
'OrderPlaced',
|
|
1960
|
-
true
|
|
1961
|
-
>,
|
|
1962
|
-
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1963
|
-
> & {
|
|
1964
|
-
/** Address of the maker to filter events. */
|
|
1965
|
-
maker?: Address | undefined
|
|
1966
|
-
/** Callback to invoke when an order is placed. */
|
|
1967
|
-
onOrderPlaced: (args: Args, log: Log) => void
|
|
1968
|
-
/** Address of the token to filter events. */
|
|
1969
|
-
token?: Address | undefined
|
|
1970
|
-
}
|
|
1971
|
-
}
|
|
1972
|
-
|
|
1973
|
-
/**
|
|
1974
|
-
* Withdraws tokens from the DEX to the caller's wallet.
|
|
1975
|
-
*
|
|
1976
|
-
* @example
|
|
1977
|
-
* ```ts
|
|
1978
|
-
* import { createClient, http } from 'viem'
|
|
1979
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1980
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1981
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1982
|
-
*
|
|
1983
|
-
* const client = createClient({
|
|
1984
|
-
* account: privateKeyToAccount('0x...'),
|
|
1985
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1986
|
-
* transport: http(),
|
|
1987
|
-
* })
|
|
1988
|
-
*
|
|
1989
|
-
* const hash = await Actions.dex.withdraw(client, {
|
|
1990
|
-
* amount: 100n,
|
|
1991
|
-
* token: '0x20c...11',
|
|
1992
|
-
* })
|
|
1993
|
-
* ```
|
|
1994
|
-
*
|
|
1995
|
-
* @param client - Client.
|
|
1996
|
-
* @param parameters - Parameters.
|
|
1997
|
-
* @returns The transaction hash.
|
|
1998
|
-
*/
|
|
1999
|
-
export async function withdraw<
|
|
2000
|
-
chain extends Chain | undefined,
|
|
2001
|
-
account extends Account | undefined,
|
|
2002
|
-
>(
|
|
2003
|
-
client: Client<Transport, chain, account>,
|
|
2004
|
-
parameters: withdraw.Parameters<chain, account>,
|
|
2005
|
-
): Promise<withdraw.ReturnValue> {
|
|
2006
|
-
return withdraw.inner(writeContract, client, parameters)
|
|
2007
|
-
}
|
|
2008
|
-
|
|
2009
|
-
export namespace withdraw {
|
|
2010
|
-
export type Parameters<
|
|
2011
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
2012
|
-
account extends Account | undefined = Account | undefined,
|
|
2013
|
-
> = WriteParameters<chain, account> & Args
|
|
2014
|
-
|
|
2015
|
-
export type Args = {
|
|
2016
|
-
/** Amount to withdraw. */
|
|
2017
|
-
amount: bigint
|
|
2018
|
-
/** Address of the token to withdraw. */
|
|
2019
|
-
token: Address
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
|
-
export type ReturnValue = WriteContractReturnType
|
|
2023
|
-
|
|
2024
|
-
// TODO: exhaustive error type
|
|
2025
|
-
export type ErrorType = BaseErrorType
|
|
2026
|
-
|
|
2027
|
-
/** @internal */
|
|
2028
|
-
export async function inner<
|
|
2029
|
-
action extends typeof writeContract | typeof writeContractSync,
|
|
2030
|
-
chain extends Chain | undefined,
|
|
2031
|
-
account extends Account | undefined,
|
|
2032
|
-
>(
|
|
2033
|
-
action: action,
|
|
2034
|
-
client: Client<Transport, chain, account>,
|
|
2035
|
-
parameters: withdraw.Parameters<chain, account>,
|
|
2036
|
-
): Promise<ReturnType<action>> {
|
|
2037
|
-
const { token, amount, ...rest } = parameters
|
|
2038
|
-
const call = withdraw.call({ token, amount })
|
|
2039
|
-
return (await action(client, {
|
|
2040
|
-
...rest,
|
|
2041
|
-
...call,
|
|
2042
|
-
} as never)) as never
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
/**
|
|
2046
|
-
* Defines a call to the `withdraw` function.
|
|
2047
|
-
*
|
|
2048
|
-
* Can be passed as a parameter to:
|
|
2049
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2050
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2051
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2052
|
-
*
|
|
2053
|
-
* @example
|
|
2054
|
-
* ```ts
|
|
2055
|
-
* import { createClient, http, parseUnits, walletActions } from 'viem'
|
|
2056
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2057
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2058
|
-
*
|
|
2059
|
-
* const client = createClient({
|
|
2060
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2061
|
-
* transport: http(),
|
|
2062
|
-
* }).extend(walletActions)
|
|
2063
|
-
*
|
|
2064
|
-
* const { result } = await client.sendCalls({
|
|
2065
|
-
* calls: [
|
|
2066
|
-
* Actions.dex.withdraw.call({
|
|
2067
|
-
* amount: parseUnits('100', 6),
|
|
2068
|
-
* token: '0x20c0...beef',
|
|
2069
|
-
* }),
|
|
2070
|
-
* ]
|
|
2071
|
-
* })
|
|
2072
|
-
* ```
|
|
2073
|
-
*
|
|
2074
|
-
* @param args - Arguments.
|
|
2075
|
-
* @returns The call.
|
|
2076
|
-
*/
|
|
2077
|
-
export function call(args: Args) {
|
|
2078
|
-
const { token, amount } = args
|
|
2079
|
-
return defineCall({
|
|
2080
|
-
address: Addresses.stablecoinExchange,
|
|
2081
|
-
abi: Abis.stablecoinExchange,
|
|
2082
|
-
functionName: 'withdraw',
|
|
2083
|
-
args: [token, amount],
|
|
2084
|
-
})
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
|
-
/**
|
|
2089
|
-
* Withdraws tokens from the DEX to the caller's wallet.
|
|
2090
|
-
*
|
|
2091
|
-
* @example
|
|
2092
|
-
* ```ts
|
|
2093
|
-
* import { createClient, http } from 'viem'
|
|
2094
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2095
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2096
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2097
|
-
*
|
|
2098
|
-
* const client = createClient({
|
|
2099
|
-
* account: privateKeyToAccount('0x...'),
|
|
2100
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2101
|
-
* transport: http(),
|
|
2102
|
-
* })
|
|
2103
|
-
*
|
|
2104
|
-
* const result = await Actions.dex.withdrawSync(client, {
|
|
2105
|
-
* amount: 100n,
|
|
2106
|
-
* token: '0x20c...11',
|
|
2107
|
-
* })
|
|
2108
|
-
* ```
|
|
2109
|
-
*
|
|
2110
|
-
* @param client - Client.
|
|
2111
|
-
* @param parameters - Parameters.
|
|
2112
|
-
* @returns The transaction receipt.
|
|
2113
|
-
*/
|
|
2114
|
-
export async function withdrawSync<
|
|
2115
|
-
chain extends Chain | undefined,
|
|
2116
|
-
account extends Account | undefined,
|
|
2117
|
-
>(
|
|
2118
|
-
client: Client<Transport, chain, account>,
|
|
2119
|
-
parameters: withdrawSync.Parameters<chain, account>,
|
|
2120
|
-
): Promise<withdrawSync.ReturnValue> {
|
|
2121
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
2122
|
-
const receipt = await withdraw.inner(writeContractSync, client, {
|
|
2123
|
-
...rest,
|
|
2124
|
-
throwOnReceiptRevert,
|
|
2125
|
-
} as never)
|
|
2126
|
-
return { receipt }
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
export namespace withdrawSync {
|
|
2130
|
-
export type Parameters<
|
|
2131
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
2132
|
-
account extends Account | undefined = Account | undefined,
|
|
2133
|
-
> = withdraw.Parameters<chain, account>
|
|
2134
|
-
|
|
2135
|
-
export type Args = withdraw.Args
|
|
2136
|
-
|
|
2137
|
-
export type ReturnValue = Compute<{
|
|
2138
|
-
/** Transaction receipt. */
|
|
2139
|
-
receipt: TransactionReceipt
|
|
2140
|
-
}>
|
|
2141
|
-
|
|
2142
|
-
// TODO: exhaustive error type
|
|
2143
|
-
export type ErrorType = BaseErrorType
|
|
2144
|
-
}
|
|
2145
|
-
|
|
2146
|
-
function getPairKey(base: Address, quote: Address) {
|
|
2147
|
-
const [tokenA, tokenB] =
|
|
2148
|
-
Hex.toBigInt(base) < Hex.toBigInt(quote) ? [base, quote] : [quote, base]
|
|
2149
|
-
return Hash.keccak256(Hex.concat(tokenA, tokenB))
|
|
2150
|
-
}
|