tempo.ts 0.6.2 → 0.7.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 +134 -0
- package/README.md +6 -2
- package/dist/ox/Transaction.js +1 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/server/Handler.d.ts +346 -0
- package/dist/server/Handler.d.ts.map +1 -0
- package/dist/server/Handler.js +441 -0
- package/dist/server/Handler.js.map +1 -0
- package/dist/server/Kv.d.ts +16 -0
- package/dist/server/Kv.d.ts.map +1 -0
- package/dist/server/Kv.js +25 -0
- package/dist/server/Kv.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/internal/requestListener.d.ts +124 -0
- package/dist/server/internal/requestListener.d.ts.map +1 -0
- package/dist/server/internal/requestListener.js +174 -0
- package/dist/server/internal/requestListener.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +9 -41
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +15 -26
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/reward.d.ts +0 -1067
- package/dist/viem/Actions/reward.d.ts.map +1 -1
- package/dist/viem/Actions/reward.js +4 -212
- package/dist/viem/Actions/reward.js.map +1 -1
- package/dist/viem/Decorator.d.ts +0 -263
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +0 -10
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Storage.d.ts +23 -0
- package/dist/viem/Storage.d.ts.map +1 -0
- package/dist/viem/Storage.js +47 -0
- package/dist/viem/Storage.js.map +1 -0
- package/dist/viem/Transport.d.ts +10 -1
- package/dist/viem/Transport.d.ts.map +1 -1
- package/dist/viem/Transport.js +22 -3
- package/dist/viem/Transport.js.map +1 -1
- package/dist/viem/internal/utils.d.ts +6 -0
- package/dist/viem/internal/utils.d.ts.map +1 -1
- package/dist/viem/internal/utils.js +24 -0
- package/dist/viem/internal/utils.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +0 -110
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +0 -121
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +6 -17
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +17 -43
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/reward.d.ts +0 -88
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
- package/dist/wagmi/Hooks/reward.js +0 -103
- package/dist/wagmi/Hooks/reward.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +57 -0
- package/dist/wagmi/KeyManager.d.ts.map +1 -0
- package/dist/wagmi/KeyManager.js +101 -0
- package/dist/wagmi/KeyManager.js.map +1 -0
- package/dist/wagmi/index.d.ts +1 -0
- package/dist/wagmi/index.d.ts.map +1 -1
- package/dist/wagmi/index.js +1 -0
- package/dist/wagmi/index.js.map +1 -1
- package/package.json +8 -2
- package/src/ox/Transaction.ts +1 -1
- package/src/ox/e2e.test.ts +7 -0
- package/src/server/Handler.test.ts +566 -0
- package/src/server/Handler.ts +577 -0
- package/src/server/Kv.ts +40 -0
- package/src/server/index.ts +2 -0
- package/src/server/internal/requestListener.ts +285 -0
- package/src/viem/Actions/amm.test.ts +10 -284
- package/src/viem/Actions/amm.ts +32 -40
- package/src/viem/Actions/reward.test.ts +4 -212
- package/src/viem/Actions/reward.ts +4 -291
- package/src/viem/Decorator.ts +0 -294
- package/src/viem/Storage.ts +88 -0
- package/src/viem/Transport.ts +40 -2
- package/src/viem/e2e.test.ts +106 -3
- package/src/viem/internal/utils.ts +21 -0
- package/src/wagmi/Actions/amm.test.ts +7 -85
- package/src/wagmi/Actions/reward.test.ts +0 -99
- package/src/wagmi/Actions/reward.ts +0 -203
- package/src/wagmi/Connector.test.ts +4 -1
- package/src/wagmi/Connector.ts +24 -58
- package/src/wagmi/Hooks/amm.test.ts +8 -200
- package/src/wagmi/Hooks/reward.test.ts +1 -142
- package/src/wagmi/Hooks/reward.ts +0 -196
- package/src/wagmi/KeyManager.ts +159 -0
- package/src/wagmi/index.ts +1 -0
package/src/viem/e2e.test.ts
CHANGED
|
@@ -41,6 +41,8 @@ describe('sendTransaction', () => {
|
|
|
41
41
|
gas,
|
|
42
42
|
gasPrice,
|
|
43
43
|
hash: hash_,
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
keyAuthorization: __,
|
|
44
46
|
maxFeePerGas,
|
|
45
47
|
maxPriorityFeePerGas,
|
|
46
48
|
nonce,
|
|
@@ -115,6 +117,8 @@ describe('sendTransaction', () => {
|
|
|
115
117
|
gas,
|
|
116
118
|
gasPrice,
|
|
117
119
|
hash: hash_,
|
|
120
|
+
// @ts-expect-error
|
|
121
|
+
keyAuthorization: __,
|
|
118
122
|
maxFeePerGas,
|
|
119
123
|
maxPriorityFeePerGas,
|
|
120
124
|
nonce,
|
|
@@ -178,6 +182,8 @@ describe('sendTransaction', () => {
|
|
|
178
182
|
gas,
|
|
179
183
|
gasPrice,
|
|
180
184
|
hash: hash_,
|
|
185
|
+
// @ts-expect-error
|
|
186
|
+
keyAuthorization: __,
|
|
181
187
|
maxFeePerGas,
|
|
182
188
|
maxPriorityFeePerGas,
|
|
183
189
|
nonce,
|
|
@@ -251,6 +257,8 @@ describe('sendTransaction', () => {
|
|
|
251
257
|
gas,
|
|
252
258
|
gasPrice,
|
|
253
259
|
hash,
|
|
260
|
+
// @ts-expect-error
|
|
261
|
+
keyAuthorization: __,
|
|
254
262
|
maxFeePerGas,
|
|
255
263
|
maxPriorityFeePerGas,
|
|
256
264
|
nonce,
|
|
@@ -333,6 +341,8 @@ describe('sendTransaction', () => {
|
|
|
333
341
|
gas,
|
|
334
342
|
gasPrice,
|
|
335
343
|
hash,
|
|
344
|
+
// @ts-expect-error
|
|
345
|
+
keyAuthorization: __,
|
|
336
346
|
maxFeePerGas,
|
|
337
347
|
maxPriorityFeePerGas,
|
|
338
348
|
nonce,
|
|
@@ -401,6 +411,8 @@ describe('sendTransaction', () => {
|
|
|
401
411
|
gas,
|
|
402
412
|
gasPrice,
|
|
403
413
|
hash: hash_,
|
|
414
|
+
// @ts-expect-error
|
|
415
|
+
keyAuthorization: __,
|
|
404
416
|
maxFeePerGas,
|
|
405
417
|
maxPriorityFeePerGas,
|
|
406
418
|
nonce,
|
|
@@ -472,6 +484,8 @@ describe('sendTransaction', () => {
|
|
|
472
484
|
from,
|
|
473
485
|
gasPrice,
|
|
474
486
|
hash,
|
|
487
|
+
// @ts-expect-error
|
|
488
|
+
keyAuthorization: __,
|
|
475
489
|
maxFeePerGas,
|
|
476
490
|
maxPriorityFeePerGas,
|
|
477
491
|
nonce,
|
|
@@ -553,6 +567,8 @@ describe('sendTransaction', () => {
|
|
|
553
567
|
gas,
|
|
554
568
|
gasPrice,
|
|
555
569
|
hash,
|
|
570
|
+
// @ts-expect-error
|
|
571
|
+
keyAuthorization: __,
|
|
556
572
|
maxFeePerGas,
|
|
557
573
|
maxPriorityFeePerGas,
|
|
558
574
|
nonce,
|
|
@@ -596,6 +612,8 @@ describe('sendTransaction', () => {
|
|
|
596
612
|
from,
|
|
597
613
|
gasPrice,
|
|
598
614
|
hash: hash_,
|
|
615
|
+
// @ts-expect-error
|
|
616
|
+
keyAuthorization: __,
|
|
599
617
|
maxFeePerGas,
|
|
600
618
|
maxPriorityFeePerGas,
|
|
601
619
|
nonce,
|
|
@@ -644,6 +662,8 @@ describe('sendTransaction', () => {
|
|
|
644
662
|
gas,
|
|
645
663
|
gasPrice,
|
|
646
664
|
hash,
|
|
665
|
+
// @ts-expect-error
|
|
666
|
+
keyAuthorization: __,
|
|
647
667
|
maxFeePerGas,
|
|
648
668
|
maxPriorityFeePerGas,
|
|
649
669
|
nonce,
|
|
@@ -730,6 +750,8 @@ describe('sendTransaction', () => {
|
|
|
730
750
|
gas,
|
|
731
751
|
gasPrice,
|
|
732
752
|
hash,
|
|
753
|
+
// @ts-expect-error
|
|
754
|
+
keyAuthorization: __,
|
|
733
755
|
maxFeePerGas,
|
|
734
756
|
maxPriorityFeePerGas,
|
|
735
757
|
nonce,
|
|
@@ -802,6 +824,8 @@ describe('sendTransaction', () => {
|
|
|
802
824
|
gas,
|
|
803
825
|
gasPrice,
|
|
804
826
|
hash: hash_,
|
|
827
|
+
// @ts-expect-error
|
|
828
|
+
keyAuthorization: __,
|
|
805
829
|
maxFeePerGas,
|
|
806
830
|
maxPriorityFeePerGas,
|
|
807
831
|
nonce,
|
|
@@ -888,6 +912,8 @@ describe('signTransaction', () => {
|
|
|
888
912
|
from,
|
|
889
913
|
gasPrice,
|
|
890
914
|
hash: hash_,
|
|
915
|
+
// @ts-expect-error
|
|
916
|
+
keyAuthorization: __,
|
|
891
917
|
maxFeePerGas,
|
|
892
918
|
maxPriorityFeePerGas,
|
|
893
919
|
nonce,
|
|
@@ -943,6 +969,7 @@ describe('relay', () => {
|
|
|
943
969
|
transport: withFeePayer(
|
|
944
970
|
http(undefined, { fetchOptions }),
|
|
945
971
|
http('http://localhost:3050'),
|
|
972
|
+
{ policy: 'sign-and-broadcast' },
|
|
946
973
|
),
|
|
947
974
|
})
|
|
948
975
|
.extend(tempoActions())
|
|
@@ -963,7 +990,9 @@ describe('relay', () => {
|
|
|
963
990
|
|
|
964
991
|
const request = RpcRequest.from(await r.json())
|
|
965
992
|
|
|
993
|
+
// Validate method
|
|
966
994
|
if (
|
|
995
|
+
(request as any).method !== 'eth_signRawTransaction' &&
|
|
967
996
|
request.method !== 'eth_sendRawTransaction' &&
|
|
968
997
|
request.method !== 'eth_sendRawTransactionSync'
|
|
969
998
|
)
|
|
@@ -972,7 +1001,7 @@ describe('relay', () => {
|
|
|
972
1001
|
{
|
|
973
1002
|
error: new RpcResponse.InvalidParamsError({
|
|
974
1003
|
message:
|
|
975
|
-
'service only supports `eth_sendRawTransaction
|
|
1004
|
+
'service only supports `eth_signTransaction`, `eth_sendRawTransaction`, and `eth_sendRawTransactionSync`',
|
|
976
1005
|
}),
|
|
977
1006
|
},
|
|
978
1007
|
{ request },
|
|
@@ -985,7 +1014,7 @@ describe('relay', () => {
|
|
|
985
1014
|
RpcResponse.from(
|
|
986
1015
|
{
|
|
987
1016
|
error: new RpcResponse.InvalidParamsError({
|
|
988
|
-
message: 'service only supports `
|
|
1017
|
+
message: 'service only supports `0x76` transactions',
|
|
989
1018
|
}),
|
|
990
1019
|
},
|
|
991
1020
|
{ request },
|
|
@@ -997,10 +1026,20 @@ describe('relay', () => {
|
|
|
997
1026
|
...transaction,
|
|
998
1027
|
feePayer: client.account,
|
|
999
1028
|
})
|
|
1029
|
+
|
|
1030
|
+
// Handle based on RPC method
|
|
1031
|
+
if ((request as any).method === 'eth_signRawTransaction') {
|
|
1032
|
+
// Policy: 'sign-only' - Return signed transaction without broadcasting
|
|
1033
|
+
return Response.json(
|
|
1034
|
+
RpcResponse.from({ result: serializedTransaction }, { request }),
|
|
1035
|
+
)
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// Policy: 'sign-and-broadcast' - Sign, broadcast, and return hash
|
|
1000
1039
|
const result = await client.request({
|
|
1001
1040
|
method: request.method,
|
|
1002
1041
|
params: [serializedTransaction],
|
|
1003
|
-
})
|
|
1042
|
+
} as never)
|
|
1004
1043
|
|
|
1005
1044
|
return Response.json(RpcResponse.from({ result }, { request }))
|
|
1006
1045
|
}),
|
|
@@ -1050,6 +1089,8 @@ describe('relay', () => {
|
|
|
1050
1089
|
gas,
|
|
1051
1090
|
gasPrice,
|
|
1052
1091
|
hash,
|
|
1092
|
+
// @ts-expect-error
|
|
1093
|
+
keyAuthorization: __,
|
|
1053
1094
|
maxFeePerGas,
|
|
1054
1095
|
maxPriorityFeePerGas,
|
|
1055
1096
|
nonce,
|
|
@@ -1129,6 +1170,8 @@ describe('relay', () => {
|
|
|
1129
1170
|
gas,
|
|
1130
1171
|
gasPrice,
|
|
1131
1172
|
hash,
|
|
1173
|
+
// @ts-expect-error
|
|
1174
|
+
keyAuthorization: __,
|
|
1132
1175
|
maxFeePerGas,
|
|
1133
1176
|
maxPriorityFeePerGas,
|
|
1134
1177
|
nonce,
|
|
@@ -1239,6 +1282,8 @@ describe('relay', () => {
|
|
|
1239
1282
|
gas,
|
|
1240
1283
|
gasPrice,
|
|
1241
1284
|
hash,
|
|
1285
|
+
// @ts-expect-error
|
|
1286
|
+
keyAuthorization: __,
|
|
1242
1287
|
maxFeePerGas,
|
|
1243
1288
|
maxPriorityFeePerGas,
|
|
1244
1289
|
nonce,
|
|
@@ -1288,4 +1333,62 @@ describe('relay', () => {
|
|
|
1288
1333
|
`)
|
|
1289
1334
|
})
|
|
1290
1335
|
})
|
|
1336
|
+
|
|
1337
|
+
describe('policy: sign-only', () => {
|
|
1338
|
+
test('relay co-signs and transport auto-submits', async () => {
|
|
1339
|
+
const signClient = getClient({
|
|
1340
|
+
transport: withFeePayer(
|
|
1341
|
+
http(undefined, { fetchOptions }),
|
|
1342
|
+
http('http://localhost:3050'),
|
|
1343
|
+
{ policy: 'sign-only' },
|
|
1344
|
+
),
|
|
1345
|
+
})
|
|
1346
|
+
.extend(tempoActions())
|
|
1347
|
+
.extend(walletActions)
|
|
1348
|
+
.extend(publicActions)
|
|
1349
|
+
|
|
1350
|
+
// unfunded account that needs sponsorship
|
|
1351
|
+
const account = privateKeyToAccount(
|
|
1352
|
+
'0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
|
|
1353
|
+
)
|
|
1354
|
+
|
|
1355
|
+
// With 'sign-only' policy, the relay co-signs and the transport auto-submits
|
|
1356
|
+
const { user, token, receipt } = await signClient.fee.setUserTokenSync({
|
|
1357
|
+
account,
|
|
1358
|
+
feePayer: true,
|
|
1359
|
+
token: 1n,
|
|
1360
|
+
})
|
|
1361
|
+
|
|
1362
|
+
// Verify the action returned the expected values
|
|
1363
|
+
expect(user).toBe(account.address)
|
|
1364
|
+
expect(token).toBe('0x20C0000000000000000000000000000000000001')
|
|
1365
|
+
expect(receipt).toBeDefined()
|
|
1366
|
+
|
|
1367
|
+
// Verify the transaction was successfully executed
|
|
1368
|
+
const userToken = await signClient.fee.getUserToken({
|
|
1369
|
+
account: account.address,
|
|
1370
|
+
})
|
|
1371
|
+
expect(userToken?.id).toBe(1n)
|
|
1372
|
+
|
|
1373
|
+
const {
|
|
1374
|
+
feePayerSignature,
|
|
1375
|
+
from,
|
|
1376
|
+
gas,
|
|
1377
|
+
gasPrice,
|
|
1378
|
+
maxFeePerGas,
|
|
1379
|
+
maxPriorityFeePerGas,
|
|
1380
|
+
signature,
|
|
1381
|
+
} = (await signClient.getTransaction({
|
|
1382
|
+
hash: receipt.transactionHash,
|
|
1383
|
+
})) as any
|
|
1384
|
+
|
|
1385
|
+
expect(feePayerSignature).toBeDefined()
|
|
1386
|
+
expect(from).toBe(account.address.toLowerCase())
|
|
1387
|
+
expect(gas).toBeDefined()
|
|
1388
|
+
expect(gasPrice).toBeDefined()
|
|
1389
|
+
expect(maxFeePerGas).toBeDefined()
|
|
1390
|
+
expect(maxPriorityFeePerGas).toBeDefined()
|
|
1391
|
+
expect(signature).toBeDefined()
|
|
1392
|
+
})
|
|
1393
|
+
})
|
|
1291
1394
|
})
|
|
@@ -35,3 +35,24 @@ export function defineCall<
|
|
|
35
35
|
to: call.address,
|
|
36
36
|
} as const
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Normalizes a value into a structured-clone compatible format.
|
|
41
|
+
*
|
|
42
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone
|
|
43
|
+
*/
|
|
44
|
+
export function normalizeValue<type>(value: type): type {
|
|
45
|
+
if (Array.isArray(value)) return value.map(normalizeValue) as never
|
|
46
|
+
if (typeof value === 'function') return undefined as never
|
|
47
|
+
if (typeof value !== 'object' || value === null) return value
|
|
48
|
+
if (Object.getPrototypeOf(value) !== Object.prototype)
|
|
49
|
+
try {
|
|
50
|
+
return structuredClone(value)
|
|
51
|
+
} catch {
|
|
52
|
+
return undefined as never
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const normalized: Record<string, unknown> = {}
|
|
56
|
+
for (const [k, v] of Object.entries(value)) normalized[k] = normalizeValue(v)
|
|
57
|
+
return normalized as never
|
|
58
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { connect
|
|
1
|
+
import { connect } from '@wagmi/core'
|
|
2
2
|
import { parseUnits } from 'viem'
|
|
3
3
|
import { describe, expect, test } from 'vitest'
|
|
4
4
|
import { addresses } from '../../../test/config.js'
|
|
5
|
-
import { accounts
|
|
5
|
+
import { accounts } from '../../../test/viem/config.js'
|
|
6
6
|
import { config, queryClient } from '../../../test/wagmi/config.js'
|
|
7
7
|
import * as ammActions from './amm.js'
|
|
8
8
|
import * as tokenActions from './token.js'
|
|
@@ -96,23 +96,18 @@ describe('mintSync', () => {
|
|
|
96
96
|
const { receipt: mintReceipt, ...mintResult } = await ammActions.mintSync(
|
|
97
97
|
config,
|
|
98
98
|
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
validatorToken: {
|
|
104
|
-
address: addresses.alphaUsd,
|
|
105
|
-
amount: parseUnits('100', 6),
|
|
106
|
-
},
|
|
99
|
+
userTokenAddress: token,
|
|
100
|
+
validatorTokenAddress: addresses.alphaUsd,
|
|
101
|
+
validatorTokenAmount: parseUnits('100', 6),
|
|
107
102
|
to: account.address,
|
|
108
103
|
},
|
|
109
104
|
)
|
|
110
105
|
expect(mintReceipt).toBeDefined()
|
|
111
106
|
expect(mintResult).toMatchInlineSnapshot(`
|
|
112
107
|
{
|
|
113
|
-
"amountUserToken":
|
|
108
|
+
"amountUserToken": 0n,
|
|
114
109
|
"amountValidatorToken": 100000000n,
|
|
115
|
-
"liquidity":
|
|
110
|
+
"liquidity": 49999000n,
|
|
116
111
|
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
117
112
|
"userToken": "0x20C0000000000000000000000000000000000004",
|
|
118
113
|
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
@@ -120,76 +115,3 @@ describe('mintSync', () => {
|
|
|
120
115
|
`)
|
|
121
116
|
})
|
|
122
117
|
})
|
|
123
|
-
|
|
124
|
-
describe('burnSync', () => {
|
|
125
|
-
test('default', async () => {
|
|
126
|
-
await connect(config, {
|
|
127
|
-
connector: config.connectors[0]!,
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
const client = await getConnectorClient(config)
|
|
131
|
-
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
132
|
-
|
|
133
|
-
// Get LP balance before burn
|
|
134
|
-
const lpBalanceBefore = await ammActions.getLiquidityBalance(config, {
|
|
135
|
-
userToken: tokenAddress,
|
|
136
|
-
validatorToken: addresses.alphaUsd,
|
|
137
|
-
address: account.address,
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
// Burn half of LP tokens
|
|
141
|
-
const { receipt: burnReceipt, ...burnResult } = await ammActions.burnSync(
|
|
142
|
-
config,
|
|
143
|
-
{
|
|
144
|
-
userToken: tokenAddress,
|
|
145
|
-
validatorToken: addresses.alphaUsd,
|
|
146
|
-
liquidity: lpBalanceBefore / 2n,
|
|
147
|
-
to: account.address,
|
|
148
|
-
},
|
|
149
|
-
)
|
|
150
|
-
expect(burnReceipt).toBeDefined()
|
|
151
|
-
expect(burnResult).toMatchInlineSnapshot(`
|
|
152
|
-
{
|
|
153
|
-
"amountUserToken": 49999999n,
|
|
154
|
-
"amountValidatorToken": 49999999n,
|
|
155
|
-
"liquidity": 2499999999999500n,
|
|
156
|
-
"sender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
157
|
-
"to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
158
|
-
"userToken": "0x20c0000000000000000000000000000000000005",
|
|
159
|
-
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
160
|
-
}
|
|
161
|
-
`)
|
|
162
|
-
})
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
describe('rebalanceSwapSync', () => {
|
|
166
|
-
test('default', async () => {
|
|
167
|
-
await connect(config, {
|
|
168
|
-
connector: config.connectors[0]!,
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
const client = await getConnectorClient(config)
|
|
172
|
-
const { tokenAddress } = await setupPoolWithLiquidity(client)
|
|
173
|
-
|
|
174
|
-
const account2 = accounts[1]
|
|
175
|
-
|
|
176
|
-
// Perform rebalance swap
|
|
177
|
-
const { receipt: swapReceipt, ...swapResult } =
|
|
178
|
-
await ammActions.rebalanceSwapSync(config, {
|
|
179
|
-
userToken: tokenAddress,
|
|
180
|
-
validatorToken: addresses.alphaUsd,
|
|
181
|
-
amountOut: parseUnits('10', 6),
|
|
182
|
-
to: account2.address,
|
|
183
|
-
})
|
|
184
|
-
expect(swapReceipt).toBeDefined()
|
|
185
|
-
expect(swapResult).toMatchInlineSnapshot(`
|
|
186
|
-
{
|
|
187
|
-
"amountIn": 9985001n,
|
|
188
|
-
"amountOut": 10000000n,
|
|
189
|
-
"swapper": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
190
|
-
"userToken": "0x20C0000000000000000000000000000000000006",
|
|
191
|
-
"validatorToken": "0x20C0000000000000000000000000000000000001",
|
|
192
|
-
}
|
|
193
|
-
`)
|
|
194
|
-
})
|
|
195
|
-
})
|
|
@@ -5,31 +5,6 @@ import { config, queryClient, setupToken } from '../../../test/wagmi/config.js'
|
|
|
5
5
|
import * as actions from './reward.js'
|
|
6
6
|
import * as tokenActions from './token.js'
|
|
7
7
|
|
|
8
|
-
describe('cancelSync', () => {
|
|
9
|
-
test('default', async () => {
|
|
10
|
-
const { token } = await setupToken()
|
|
11
|
-
|
|
12
|
-
// Start a reward stream
|
|
13
|
-
const rewardAmount = parseUnits('100', 6)
|
|
14
|
-
const { id: streamId } = await actions.startSync(config, {
|
|
15
|
-
amount: rewardAmount,
|
|
16
|
-
seconds: 3600,
|
|
17
|
-
token,
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
// Cancel the reward
|
|
21
|
-
const { receipt, refund, ...result } = await actions.cancelSync(config, {
|
|
22
|
-
id: streamId,
|
|
23
|
-
token,
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
expect(refund).toBeGreaterThan(0n)
|
|
27
|
-
expect(receipt).toBeDefined()
|
|
28
|
-
expect(result.funder).toBeDefined()
|
|
29
|
-
expect(result.id).toBe(streamId)
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
8
|
// TODO: unskip
|
|
34
9
|
describe.skip('claimSync', () => {
|
|
35
10
|
test('default', async () => {
|
|
@@ -59,7 +34,6 @@ describe.skip('claimSync', () => {
|
|
|
59
34
|
// Start immediate reward
|
|
60
35
|
await actions.startSync(config, {
|
|
61
36
|
amount: rewardAmount,
|
|
62
|
-
seconds: 0,
|
|
63
37
|
token,
|
|
64
38
|
})
|
|
65
39
|
|
|
@@ -89,55 +63,6 @@ describe.skip('claimSync', () => {
|
|
|
89
63
|
})
|
|
90
64
|
})
|
|
91
65
|
|
|
92
|
-
describe('getStream', () => {
|
|
93
|
-
test('default', async () => {
|
|
94
|
-
const { token } = await setupToken()
|
|
95
|
-
|
|
96
|
-
// Start a reward stream
|
|
97
|
-
const rewardAmount = parseUnits('100', 6)
|
|
98
|
-
const { id: streamId } = await actions.startSync(config, {
|
|
99
|
-
amount: rewardAmount,
|
|
100
|
-
seconds: 10,
|
|
101
|
-
token,
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
// Get the stream
|
|
105
|
-
const stream = await actions.getStream(config, {
|
|
106
|
-
id: streamId,
|
|
107
|
-
token,
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
expect(stream.funder).toBeDefined()
|
|
111
|
-
expect(stream.amountTotal).toBe(rewardAmount)
|
|
112
|
-
expect(stream.endTime).toBeGreaterThan(stream.startTime)
|
|
113
|
-
expect(stream.ratePerSecondScaled).toBeGreaterThan(0n)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
describe('queryOptions', () => {
|
|
117
|
-
test('default', async () => {
|
|
118
|
-
const { token } = await setupToken()
|
|
119
|
-
|
|
120
|
-
// Start a reward stream
|
|
121
|
-
const rewardAmount = parseUnits('100', 6)
|
|
122
|
-
const { id: streamId } = await actions.startSync(config, {
|
|
123
|
-
amount: rewardAmount,
|
|
124
|
-
seconds: 10,
|
|
125
|
-
token,
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
const options = actions.getStream.queryOptions(config, {
|
|
129
|
-
id: streamId,
|
|
130
|
-
token,
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const stream = await queryClient.fetchQuery(options)
|
|
134
|
-
|
|
135
|
-
expect(stream.funder).toBeDefined()
|
|
136
|
-
expect(stream.amountTotal).toBe(rewardAmount)
|
|
137
|
-
})
|
|
138
|
-
})
|
|
139
|
-
})
|
|
140
|
-
|
|
141
66
|
describe('getTotalPerSecond', () => {
|
|
142
67
|
test('default', async () => {
|
|
143
68
|
const { token } = await setupToken()
|
|
@@ -184,27 +109,3 @@ describe('setRecipientSync', () => {
|
|
|
184
109
|
expect(recipient).toBe(account.address)
|
|
185
110
|
})
|
|
186
111
|
})
|
|
187
|
-
|
|
188
|
-
describe('startSync', () => {
|
|
189
|
-
test('default', async () => {
|
|
190
|
-
const { token } = await setupToken()
|
|
191
|
-
|
|
192
|
-
const account = getAccount(config)
|
|
193
|
-
|
|
194
|
-
// Start a reward stream
|
|
195
|
-
const rewardAmount = parseUnits('100', 6)
|
|
196
|
-
const duration = 10
|
|
197
|
-
const { amount, durationSeconds, funder, id, receipt } =
|
|
198
|
-
await actions.startSync(config, {
|
|
199
|
-
amount: rewardAmount,
|
|
200
|
-
seconds: duration,
|
|
201
|
-
token,
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
expect(receipt).toBeDefined()
|
|
205
|
-
expect(funder).toBe(account.address)
|
|
206
|
-
expect(id).toBeGreaterThan(0n)
|
|
207
|
-
expect(amount).toBe(rewardAmount)
|
|
208
|
-
expect(durationSeconds).toBe(duration)
|
|
209
|
-
})
|
|
210
|
-
})
|