@myx-trade/sdk 0.1.57 → 0.1.59

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/dist/index.mjs CHANGED
@@ -1375,6 +1375,7 @@ function isSupportedChainFn(chainId) {
1375
1375
 
1376
1376
  // src/config/address/ARB_TEST_SEPOLIA.ts
1377
1377
  var ARB_TEST_SEPOLIA = {
1378
+ USDC: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
1378
1379
  POOL_MANAGER: "0xA4A1dfbe40cB725A79D34bd529f0C1b54AB46954",
1379
1380
  Account: "0x6136899e8c77C452bc46AcD786aA2C09fD31f947",
1380
1381
  POSITION_MANAGER: "0x002F28be205E9A1e279d2eeF1f5e472CeA1d910C",
@@ -1385,14 +1386,13 @@ var ARB_TEST_SEPOLIA = {
1385
1386
  LIQUIDITY_ROUTER: "0xd185C3f675d991735FCF6885Ff6BADE02A21313d",
1386
1387
  BASE_POOL: "0x2c6AdaE4A01836487842b7369c1db3F441871E83",
1387
1388
  QUOTE_POOL: "0xe1Ff495206635570A8Eaf9517125Ce66a2d09d32",
1388
- BROKER: "0xB3DaeFF433c005e214D6cd73C35cD4bBCe7f94fD",
1389
- // MYXBroker
1390
1389
  ORACLE: "0x574001F6cB520b15d5a6db9F7B7a0ebf1A8E25c0",
1391
1390
  // MYXOracle
1392
1391
  EIP7702Delegation: "0x4e1B9aDf5Aa4a893f578c8502E6E28841b2403f3",
1393
1392
  MARKET_MANAGER: "0x12AD75316A92a66b92c79080c555594314e7aFB3",
1394
1393
  DATA_PROVIDER: "0x726A4978eDcb974B9889BC6f5Ee2Ec06D703038E",
1395
- ORACLE_RESERVE: "0xC46b81c38091933f4811EC16E93553f9801EB863"
1394
+ ORACLE_RESERVE: "0xC46b81c38091933f4811EC16E93553f9801EB863",
1395
+ FORWARDER: "0xD41c2078fe35c8ca5f95b28Ed3017C4f7b4Bd49d"
1396
1396
  };
1397
1397
 
1398
1398
  // src/config/address/LINEA_SEPOLIA.ts
@@ -1403,18 +1403,18 @@ var LINEA_SEPOLIA = {
1403
1403
  ORDER_MANAGER: "0x50602673C3506AFF2e7Df82dB6E93B6B134331Ae",
1404
1404
  PYTH: "0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",
1405
1405
  // !!! 非Pyth Adapter
1406
- ERC20: "0x635eC74A4A39A27177310F0d605515D9df4bDe43",
1406
+ ERC20: "0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",
1407
1407
  LIQUIDITY_ROUTER: "0x7fa9B7C0D95E19f180A2bf359d980c0bD3aC2503",
1408
1408
  BASE_POOL: "0x6d3A2AB082388C35319007a2D635Cf7A8B8aF0E1",
1409
1409
  QUOTE_POOL: "0x5A6fdFD381B76eD163b60300E619F7EB6049e7bD",
1410
- BROKER: "0x0C6358400a8d86d8377640B1B783b8326b7D0fdc",
1411
- // MYXBroker
1412
1410
  ORACLE: "0xfbA4a141bb3BbD0EB34b24152caa3d2940629545",
1413
1411
  // MYXOracle
1414
1412
  EIP7702Delegation: "0xa55149B66A7fC4a4eF05c8da981E46Fe27695E6c",
1415
1413
  MARKET_MANAGER: "0x96Dd73d94c7359e92a45Ff75bC90909E66332990",
1416
1414
  DATA_PROVIDER: "0xF10B5736EA756488139135BF14aE5A542de435a9",
1417
- ORACLE_RESERVE: "0xb9433C0e23f38E8Ad48B9A6e562F0a543e06a9F4"
1415
+ ORACLE_RESERVE: "0xb9433C0e23f38E8Ad48B9A6e562F0a543e06a9F4",
1416
+ USDC: "0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",
1417
+ FORWARDER: "0xeDb8E5B27baB3125b5039fB4A9e3dCc962155d2E"
1418
1418
  };
1419
1419
 
1420
1420
  // src/config/address.ts
@@ -1473,6 +1473,7 @@ var linea_default = "./linea-ZTA3FOH3.png";
1473
1473
 
1474
1474
  // src/config/fee.ts
1475
1475
  var GAS_FEE_RESERVED_RATIO = 10;
1476
+ var SEAMLESS_ACCOUNT_GAS_LIMIT = 5e6;
1476
1477
 
1477
1478
  // src/config/chains/LINEA_SEPOLIA.ts
1478
1479
  var LINEA_SEPOLIA_default = {
@@ -1751,7 +1752,7 @@ var RotationProvider = class extends BaseProvider {
1751
1752
  // package.json
1752
1753
  var package_default = {
1753
1754
  name: "@myx-trade/sdk",
1754
- version: "0.1.57",
1755
+ version: "0.1.59",
1755
1756
  private: false,
1756
1757
  publishConfig: {
1757
1758
  access: "public"
@@ -1810,6 +1811,7 @@ var package_default = {
1810
1811
  typescript: "^5.3.0"
1811
1812
  },
1812
1813
  dependencies: {
1814
+ "@ethersproject/bytes": "^5.8.0",
1813
1815
  "@ethersproject/providers": "^5.8.0",
1814
1816
  "@types/ws": "^8.18.1",
1815
1817
  "crypto-js": "^4.2.0",
@@ -1820,7 +1822,8 @@ var package_default = {
1820
1822
  "reconnecting-websocket": "^4.4.0",
1821
1823
  viem: "^2.36.0",
1822
1824
  wretch: "^2.11.0",
1823
- ws: "^8.18.3"
1825
+ ws: "^8.18.3",
1826
+ dayjs: "^1.11.13"
1824
1827
  }
1825
1828
  };
1826
1829
 
@@ -2044,8 +2047,36 @@ var getTradeFlow = async ({
2044
2047
  );
2045
2048
  };
2046
2049
 
2050
+ // src/api/seamless/index.ts
2051
+ var forwarderTxApi = async (params, chainId) => {
2052
+ console.log("forwarderTxApi params-->", params);
2053
+ return http.post(
2054
+ `${forwardUrl}/forwarder/tx-v2`,
2055
+ params,
2056
+ {
2057
+ headers: {
2058
+ "myx-chain-id": chainId.toString()
2059
+ }
2060
+ }
2061
+ );
2062
+ };
2063
+ var ForwarderGetStatus = /* @__PURE__ */ ((ForwarderGetStatus2) => {
2064
+ ForwarderGetStatus2[ForwarderGetStatus2["EXECUTING"] = 1] = "EXECUTING";
2065
+ ForwarderGetStatus2[ForwarderGetStatus2["BROADCAST_FAILED"] = 2] = "BROADCAST_FAILED";
2066
+ ForwarderGetStatus2[ForwarderGetStatus2["TIMEOUT_CANCEL"] = 3] = "TIMEOUT_CANCEL";
2067
+ ForwarderGetStatus2[ForwarderGetStatus2["EXECUTED"] = 9] = "EXECUTED";
2068
+ return ForwarderGetStatus2;
2069
+ })(ForwarderGetStatus || {});
2070
+ var fetchForwarderGetApi = async (params) => {
2071
+ const rs = await http.get(
2072
+ `${forwardUrl}/forwarder/get${addQueryParams(params)}`
2073
+ );
2074
+ return rs;
2075
+ };
2076
+
2047
2077
  // src/api/index.ts
2048
2078
  var baseUrl = "https://api-test.myx.cash";
2079
+ var forwardUrl = "https://api-test.myx.cash/v2/agent";
2049
2080
  var getOraclePrice = async (chainId, poolIds = []) => {
2050
2081
  if (!!poolIds.length) {
2051
2082
  return http.get(`${baseUrl}/openapi/gateway/quote/price/oracles`, {
@@ -9867,91 +9898,1291 @@ var DataProvider_default = [
9867
9898
  },
9868
9899
  {
9869
9900
  type: "uint256",
9870
- name: "price"
9901
+ name: "price"
9902
+ }
9903
+ ],
9904
+ outputs: [
9905
+ {
9906
+ type: "int256",
9907
+ name: "netCollateral"
9908
+ },
9909
+ {
9910
+ type: "uint256",
9911
+ name: "collateralAmount"
9912
+ },
9913
+ {
9914
+ type: "uint256",
9915
+ name: "tradingFee"
9916
+ },
9917
+ {
9918
+ type: "int256",
9919
+ name: "fundingFee"
9920
+ }
9921
+ ]
9922
+ },
9923
+ {
9924
+ type: "function",
9925
+ name: "getUserPositionInfos",
9926
+ constant: true,
9927
+ stateMutability: "view",
9928
+ payable: false,
9929
+ inputs: [
9930
+ {
9931
+ type: "address",
9932
+ name: "user"
9933
+ },
9934
+ {
9935
+ type: "bytes32[]",
9936
+ name: "poolIds"
9937
+ }
9938
+ ],
9939
+ outputs: [
9940
+ {
9941
+ type: "tuple[]",
9942
+ name: "positions",
9943
+ components: [
9944
+ {
9945
+ type: "bytes32",
9946
+ name: "positionId"
9947
+ },
9948
+ {
9949
+ type: "bytes32",
9950
+ name: "poolId"
9951
+ },
9952
+ {
9953
+ type: "uint256",
9954
+ name: "size"
9955
+ },
9956
+ {
9957
+ type: "uint256",
9958
+ name: "entryPrice"
9959
+ },
9960
+ {
9961
+ type: "int256",
9962
+ name: "fundingRateIndex"
9963
+ },
9964
+ {
9965
+ type: "uint256",
9966
+ name: "earlyClosePrice"
9967
+ },
9968
+ {
9969
+ type: "uint8",
9970
+ name: "direction"
9971
+ },
9972
+ {
9973
+ type: "uint8",
9974
+ name: "riskTier"
9975
+ },
9976
+ {
9977
+ type: "uint64",
9978
+ name: "lastUpdateTime"
9979
+ },
9980
+ {
9981
+ type: "uint256",
9982
+ name: "collateralAmount"
9983
+ }
9984
+ ]
9985
+ }
9986
+ ]
9987
+ }
9988
+ ];
9989
+
9990
+ // src/abi/Forwarder.json
9991
+ var Forwarder_default = [
9992
+ {
9993
+ type: "constructor",
9994
+ payable: false,
9995
+ inputs: []
9996
+ },
9997
+ {
9998
+ type: "error",
9999
+ name: "AddressEmptyCode",
10000
+ inputs: [
10001
+ {
10002
+ type: "address",
10003
+ name: "target"
10004
+ }
10005
+ ]
10006
+ },
10007
+ {
10008
+ type: "error",
10009
+ name: "ERC1967InvalidImplementation",
10010
+ inputs: [
10011
+ {
10012
+ type: "address",
10013
+ name: "implementation"
10014
+ }
10015
+ ]
10016
+ },
10017
+ {
10018
+ type: "error",
10019
+ name: "ERC1967NonPayable",
10020
+ inputs: []
10021
+ },
10022
+ {
10023
+ type: "error",
10024
+ name: "ERC2771ForwarderExpiredRequest",
10025
+ inputs: [
10026
+ {
10027
+ type: "uint48",
10028
+ name: "deadline"
10029
+ }
10030
+ ]
10031
+ },
10032
+ {
10033
+ type: "error",
10034
+ name: "ERC2771ForwarderInvalidSigner",
10035
+ inputs: [
10036
+ {
10037
+ type: "address",
10038
+ name: "signer"
10039
+ },
10040
+ {
10041
+ type: "address",
10042
+ name: "from"
10043
+ }
10044
+ ]
10045
+ },
10046
+ {
10047
+ type: "error",
10048
+ name: "ERC2771ForwarderMismatchedValue",
10049
+ inputs: [
10050
+ {
10051
+ type: "uint256",
10052
+ name: "requestedValue"
10053
+ },
10054
+ {
10055
+ type: "uint256",
10056
+ name: "msgValue"
10057
+ }
10058
+ ]
10059
+ },
10060
+ {
10061
+ type: "error",
10062
+ name: "ERC2771UntrustfulTarget",
10063
+ inputs: [
10064
+ {
10065
+ type: "address",
10066
+ name: "target"
10067
+ },
10068
+ {
10069
+ type: "address",
10070
+ name: "forwarder"
10071
+ }
10072
+ ]
10073
+ },
10074
+ {
10075
+ type: "error",
10076
+ name: "ExceedsMaximumRelayFee",
10077
+ inputs: []
10078
+ },
10079
+ {
10080
+ type: "error",
10081
+ name: "FailedCall",
10082
+ inputs: []
10083
+ },
10084
+ {
10085
+ type: "error",
10086
+ name: "InconsistentParamsLength",
10087
+ inputs: []
10088
+ },
10089
+ {
10090
+ type: "error",
10091
+ name: "InsufficientBalance",
10092
+ inputs: [
10093
+ {
10094
+ type: "uint256",
10095
+ name: "balance"
10096
+ },
10097
+ {
10098
+ type: "uint256",
10099
+ name: "needed"
10100
+ }
10101
+ ]
10102
+ },
10103
+ {
10104
+ type: "error",
10105
+ name: "InsufficientFeeAllowance",
10106
+ inputs: [
10107
+ {
10108
+ type: "address",
10109
+ name: "user"
10110
+ },
10111
+ {
10112
+ type: "uint256",
10113
+ name: "allowance"
10114
+ },
10115
+ {
10116
+ type: "uint256",
10117
+ name: "required"
10118
+ }
10119
+ ]
10120
+ },
10121
+ {
10122
+ type: "error",
10123
+ name: "InsufficientFeeBalance",
10124
+ inputs: [
10125
+ {
10126
+ type: "address",
10127
+ name: "user"
10128
+ },
10129
+ {
10130
+ type: "uint256",
10131
+ name: "balance"
10132
+ },
10133
+ {
10134
+ type: "uint256",
10135
+ name: "required"
10136
+ }
10137
+ ]
10138
+ },
10139
+ {
10140
+ type: "error",
10141
+ name: "InvalidAccountNonce",
10142
+ inputs: [
10143
+ {
10144
+ type: "address",
10145
+ name: "account"
10146
+ },
10147
+ {
10148
+ type: "uint256",
10149
+ name: "currentNonce"
10150
+ }
10151
+ ]
10152
+ },
10153
+ {
10154
+ type: "error",
10155
+ name: "InvalidInitialization",
10156
+ inputs: []
10157
+ },
10158
+ {
10159
+ type: "error",
10160
+ name: "MismatchedSender",
10161
+ inputs: [
10162
+ {
10163
+ type: "address",
10164
+ name: "sender"
10165
+ }
10166
+ ]
10167
+ },
10168
+ {
10169
+ type: "error",
10170
+ name: "NotAddressManager",
10171
+ inputs: []
10172
+ },
10173
+ {
10174
+ type: "error",
10175
+ name: "NotAllowedTarget",
10176
+ inputs: [
10177
+ {
10178
+ type: "address",
10179
+ name: "target"
10180
+ }
10181
+ ]
10182
+ },
10183
+ {
10184
+ type: "error",
10185
+ name: "NotDependencyManager",
10186
+ inputs: []
10187
+ },
10188
+ {
10189
+ type: "error",
10190
+ name: "NotInitializing",
10191
+ inputs: []
10192
+ },
10193
+ {
10194
+ type: "error",
10195
+ name: "NotProxyAdmin",
10196
+ inputs: []
10197
+ },
10198
+ {
10199
+ type: "error",
10200
+ name: "OnlyRelayer",
10201
+ inputs: []
10202
+ },
10203
+ {
10204
+ type: "error",
10205
+ name: "PermissionDenied",
10206
+ inputs: [
10207
+ {
10208
+ type: "address",
10209
+ name: "caller"
10210
+ },
10211
+ {
10212
+ type: "address",
10213
+ name: "target"
10214
+ }
10215
+ ]
10216
+ },
10217
+ {
10218
+ type: "error",
10219
+ name: "ReentrancyGuardReentrantCall",
10220
+ inputs: []
10221
+ },
10222
+ {
10223
+ type: "error",
10224
+ name: "RelayerRegistered",
10225
+ inputs: [
10226
+ {
10227
+ type: "address",
10228
+ name: "relayer"
10229
+ }
10230
+ ]
10231
+ },
10232
+ {
10233
+ type: "error",
10234
+ name: "SafeERC20FailedOperation",
10235
+ inputs: [
10236
+ {
10237
+ type: "address",
10238
+ name: "token"
10239
+ }
10240
+ ]
10241
+ },
10242
+ {
10243
+ type: "error",
10244
+ name: "UUPSUnauthorizedCallContext",
10245
+ inputs: []
10246
+ },
10247
+ {
10248
+ type: "error",
10249
+ name: "UUPSUnsupportedProxiableUUID",
10250
+ inputs: [
10251
+ {
10252
+ type: "bytes32",
10253
+ name: "slot"
10254
+ }
10255
+ ]
10256
+ },
10257
+ {
10258
+ type: "event",
10259
+ anonymous: false,
10260
+ name: "AddAllowedTarget",
10261
+ inputs: [
10262
+ {
10263
+ type: "address",
10264
+ name: "target",
10265
+ indexed: false
10266
+ }
10267
+ ]
10268
+ },
10269
+ {
10270
+ type: "event",
10271
+ anonymous: false,
10272
+ name: "EIP712DomainChanged",
10273
+ inputs: []
10274
+ },
10275
+ {
10276
+ type: "event",
10277
+ anonymous: false,
10278
+ name: "ERC20PermitFailed",
10279
+ inputs: [
10280
+ {
10281
+ type: "address",
10282
+ name: "token",
10283
+ indexed: false
10284
+ },
10285
+ {
10286
+ type: "string",
10287
+ name: "reason",
10288
+ indexed: false
10289
+ }
10290
+ ]
10291
+ },
10292
+ {
10293
+ type: "event",
10294
+ anonymous: false,
10295
+ name: "ERC20PermitLowLevelFailed",
10296
+ inputs: [
10297
+ {
10298
+ type: "bytes",
10299
+ name: "data",
10300
+ indexed: false
10301
+ }
10302
+ ]
10303
+ },
10304
+ {
10305
+ type: "event",
10306
+ anonymous: false,
10307
+ name: "ExecutedForwardRequest",
10308
+ inputs: [
10309
+ {
10310
+ type: "address",
10311
+ name: "signer",
10312
+ indexed: true
10313
+ },
10314
+ {
10315
+ type: "uint256",
10316
+ name: "nonce",
10317
+ indexed: false
10318
+ },
10319
+ {
10320
+ type: "bool",
10321
+ name: "success",
10322
+ indexed: false
10323
+ }
10324
+ ]
10325
+ },
10326
+ {
10327
+ type: "event",
10328
+ anonymous: false,
10329
+ name: "Initialized",
10330
+ inputs: [
10331
+ {
10332
+ type: "uint64",
10333
+ name: "version",
10334
+ indexed: false
10335
+ }
10336
+ ]
10337
+ },
10338
+ {
10339
+ type: "event",
10340
+ anonymous: false,
10341
+ name: "RemoveAllowedTarget",
10342
+ inputs: [
10343
+ {
10344
+ type: "address",
10345
+ name: "target",
10346
+ indexed: false
10347
+ }
10348
+ ]
10349
+ },
10350
+ {
10351
+ type: "event",
10352
+ anonymous: false,
10353
+ name: "SetUserRelayer",
10354
+ inputs: [
10355
+ {
10356
+ type: "address",
10357
+ name: "account",
10358
+ indexed: false
10359
+ },
10360
+ {
10361
+ type: "address",
10362
+ name: "relayer",
10363
+ indexed: false
10364
+ },
10365
+ {
10366
+ type: "bool",
10367
+ name: "enable",
10368
+ indexed: false
10369
+ }
10370
+ ]
10371
+ },
10372
+ {
10373
+ type: "event",
10374
+ anonymous: false,
10375
+ name: "UpdateMaxRelayFee",
10376
+ inputs: [
10377
+ {
10378
+ type: "address",
10379
+ name: "sender",
10380
+ indexed: false
10381
+ },
10382
+ {
10383
+ type: "uint256",
10384
+ name: "oldMaxRelayFee",
10385
+ indexed: false
10386
+ },
10387
+ {
10388
+ type: "uint256",
10389
+ name: "newMaxRelayFee",
10390
+ indexed: false
10391
+ }
10392
+ ]
10393
+ },
10394
+ {
10395
+ type: "event",
10396
+ anonymous: false,
10397
+ name: "UpdateRelayInfo",
10398
+ inputs: [
10399
+ {
10400
+ type: "address",
10401
+ name: "sender",
10402
+ indexed: false
10403
+ },
10404
+ {
10405
+ type: "uint256",
10406
+ name: "oldRelayFee",
10407
+ indexed: false
10408
+ },
10409
+ {
10410
+ type: "uint256",
10411
+ name: "newRelayFee",
10412
+ indexed: false
10413
+ },
10414
+ {
10415
+ type: "uint256",
10416
+ name: "oldRelayGas",
10417
+ indexed: false
10418
+ },
10419
+ {
10420
+ type: "uint256",
10421
+ name: "newRelayGas",
10422
+ indexed: false
10423
+ }
10424
+ ]
10425
+ },
10426
+ {
10427
+ type: "event",
10428
+ anonymous: false,
10429
+ name: "Upgraded",
10430
+ inputs: [
10431
+ {
10432
+ type: "address",
10433
+ name: "implementation",
10434
+ indexed: true
10435
+ }
10436
+ ]
10437
+ },
10438
+ {
10439
+ type: "function",
10440
+ name: "UPGRADE_INTERFACE_VERSION",
10441
+ constant: true,
10442
+ stateMutability: "view",
10443
+ payable: false,
10444
+ inputs: [],
10445
+ outputs: [
10446
+ {
10447
+ type: "string"
10448
+ }
10449
+ ]
10450
+ },
10451
+ {
10452
+ type: "function",
10453
+ name: "__ERC2771ContextUpgradeable_init",
10454
+ constant: false,
10455
+ payable: false,
10456
+ inputs: [
10457
+ {
10458
+ type: "address",
10459
+ name: "trustedForwarder_"
10460
+ }
10461
+ ],
10462
+ outputs: []
10463
+ },
10464
+ {
10465
+ type: "function",
10466
+ name: "addAllowedTarget",
10467
+ constant: false,
10468
+ payable: false,
10469
+ inputs: [
10470
+ {
10471
+ type: "address",
10472
+ name: "target"
10473
+ }
10474
+ ],
10475
+ outputs: []
10476
+ },
10477
+ {
10478
+ type: "function",
10479
+ name: "batchExecuteForwarder",
10480
+ constant: false,
10481
+ stateMutability: "payable",
10482
+ payable: true,
10483
+ inputs: [
10484
+ {
10485
+ type: "tuple[]",
10486
+ name: "bundleParams",
10487
+ components: [
10488
+ {
10489
+ type: "address",
10490
+ name: "from"
10491
+ },
10492
+ {
10493
+ type: "address",
10494
+ name: "to"
10495
+ },
10496
+ {
10497
+ type: "uint256",
10498
+ name: "value"
10499
+ },
10500
+ {
10501
+ type: "uint256",
10502
+ name: "gas"
10503
+ },
10504
+ {
10505
+ type: "uint48",
10506
+ name: "deadline"
10507
+ },
10508
+ {
10509
+ type: "bytes",
10510
+ name: "data"
10511
+ },
10512
+ {
10513
+ type: "bytes",
10514
+ name: "signature"
10515
+ }
10516
+ ]
10517
+ }
10518
+ ],
10519
+ outputs: []
10520
+ },
10521
+ {
10522
+ type: "function",
10523
+ name: "eip712Domain",
10524
+ constant: true,
10525
+ stateMutability: "view",
10526
+ payable: false,
10527
+ inputs: [],
10528
+ outputs: [
10529
+ {
10530
+ type: "bytes1",
10531
+ name: "fields"
10532
+ },
10533
+ {
10534
+ type: "string",
10535
+ name: "name"
10536
+ },
10537
+ {
10538
+ type: "string",
10539
+ name: "version"
10540
+ },
10541
+ {
10542
+ type: "uint256",
10543
+ name: "chainId"
10544
+ },
10545
+ {
10546
+ type: "address",
10547
+ name: "verifyingContract"
10548
+ },
10549
+ {
10550
+ type: "bytes32",
10551
+ name: "salt"
10552
+ },
10553
+ {
10554
+ type: "uint256[]",
10555
+ name: "extensions"
10556
+ }
10557
+ ]
10558
+ },
10559
+ {
10560
+ type: "function",
10561
+ name: "execute",
10562
+ constant: false,
10563
+ stateMutability: "payable",
10564
+ payable: true,
10565
+ inputs: [
10566
+ {
10567
+ type: "tuple",
10568
+ name: "request",
10569
+ components: [
10570
+ {
10571
+ type: "address",
10572
+ name: "from"
10573
+ },
10574
+ {
10575
+ type: "address",
10576
+ name: "to"
10577
+ },
10578
+ {
10579
+ type: "uint256",
10580
+ name: "value"
10581
+ },
10582
+ {
10583
+ type: "uint256",
10584
+ name: "gas"
10585
+ },
10586
+ {
10587
+ type: "uint48",
10588
+ name: "deadline"
10589
+ },
10590
+ {
10591
+ type: "bytes",
10592
+ name: "data"
10593
+ },
10594
+ {
10595
+ type: "bytes",
10596
+ name: "signature"
10597
+ }
10598
+ ]
10599
+ }
10600
+ ],
10601
+ outputs: []
10602
+ },
10603
+ {
10604
+ type: "function",
10605
+ name: "executeBatch",
10606
+ constant: false,
10607
+ stateMutability: "payable",
10608
+ payable: true,
10609
+ inputs: [
10610
+ {
10611
+ type: "tuple[]",
10612
+ name: "requests",
10613
+ components: [
10614
+ {
10615
+ type: "address",
10616
+ name: "from"
10617
+ },
10618
+ {
10619
+ type: "address",
10620
+ name: "to"
10621
+ },
10622
+ {
10623
+ type: "uint256",
10624
+ name: "value"
10625
+ },
10626
+ {
10627
+ type: "uint256",
10628
+ name: "gas"
10629
+ },
10630
+ {
10631
+ type: "uint48",
10632
+ name: "deadline"
10633
+ },
10634
+ {
10635
+ type: "bytes",
10636
+ name: "data"
10637
+ },
10638
+ {
10639
+ type: "bytes",
10640
+ name: "signature"
10641
+ }
10642
+ ]
10643
+ },
10644
+ {
10645
+ type: "address",
10646
+ name: "refundReceiver"
10647
+ }
10648
+ ],
10649
+ outputs: []
10650
+ },
10651
+ {
10652
+ type: "function",
10653
+ name: "executeForwarder",
10654
+ constant: false,
10655
+ stateMutability: "payable",
10656
+ payable: true,
10657
+ inputs: [
10658
+ {
10659
+ type: "tuple",
10660
+ name: "params",
10661
+ components: [
10662
+ {
10663
+ type: "address",
10664
+ name: "from"
10665
+ },
10666
+ {
10667
+ type: "address",
10668
+ name: "to"
10669
+ },
10670
+ {
10671
+ type: "uint256",
10672
+ name: "value"
10673
+ },
10674
+ {
10675
+ type: "uint256",
10676
+ name: "gas"
10677
+ },
10678
+ {
10679
+ type: "uint48",
10680
+ name: "deadline"
10681
+ },
10682
+ {
10683
+ type: "bytes",
10684
+ name: "data"
10685
+ },
10686
+ {
10687
+ type: "bytes",
10688
+ name: "signature"
10689
+ }
10690
+ ]
10691
+ }
10692
+ ],
10693
+ outputs: []
10694
+ },
10695
+ {
10696
+ type: "function",
10697
+ name: "feeToken",
10698
+ constant: true,
10699
+ stateMutability: "view",
10700
+ payable: false,
10701
+ inputs: [],
10702
+ outputs: [
10703
+ {
10704
+ type: "address"
10705
+ }
10706
+ ]
10707
+ },
10708
+ {
10709
+ type: "function",
10710
+ name: "getAddressManager",
10711
+ constant: true,
10712
+ stateMutability: "view",
10713
+ payable: false,
10714
+ inputs: [],
10715
+ outputs: [
10716
+ {
10717
+ type: "address"
10718
+ }
10719
+ ]
10720
+ },
10721
+ {
10722
+ type: "function",
10723
+ name: "getAllowedTargets",
10724
+ constant: true,
10725
+ stateMutability: "view",
10726
+ payable: false,
10727
+ inputs: [],
10728
+ outputs: [
10729
+ {
10730
+ type: "address[]"
10731
+ }
10732
+ ]
10733
+ },
10734
+ {
10735
+ type: "function",
10736
+ name: "getDependencyAddress",
10737
+ constant: true,
10738
+ stateMutability: "view",
10739
+ payable: false,
10740
+ inputs: [
10741
+ {
10742
+ type: "bytes32",
10743
+ name: "identifier"
10744
+ }
10745
+ ],
10746
+ outputs: [
10747
+ {
10748
+ type: "address"
10749
+ }
10750
+ ]
10751
+ },
10752
+ {
10753
+ type: "function",
10754
+ name: "getFeeToken",
10755
+ constant: true,
10756
+ stateMutability: "view",
10757
+ payable: false,
10758
+ inputs: [],
10759
+ outputs: [
10760
+ {
10761
+ type: "address"
10762
+ }
10763
+ ]
10764
+ },
10765
+ {
10766
+ type: "function",
10767
+ name: "getImplementation",
10768
+ constant: true,
10769
+ stateMutability: "view",
10770
+ payable: false,
10771
+ inputs: [],
10772
+ outputs: [
10773
+ {
10774
+ type: "address"
10775
+ }
10776
+ ]
10777
+ },
10778
+ {
10779
+ type: "function",
10780
+ name: "getMaxRelayFee",
10781
+ constant: true,
10782
+ stateMutability: "view",
10783
+ payable: false,
10784
+ inputs: [],
10785
+ outputs: [
10786
+ {
10787
+ type: "uint256"
10788
+ }
10789
+ ]
10790
+ },
10791
+ {
10792
+ type: "function",
10793
+ name: "getRelayFee",
10794
+ constant: true,
10795
+ stateMutability: "view",
10796
+ payable: false,
10797
+ inputs: [],
10798
+ outputs: [
10799
+ {
10800
+ type: "uint256"
10801
+ }
10802
+ ]
10803
+ },
10804
+ {
10805
+ type: "function",
10806
+ name: "getRelayGas",
10807
+ constant: true,
10808
+ stateMutability: "view",
10809
+ payable: false,
10810
+ inputs: [],
10811
+ outputs: [
10812
+ {
10813
+ type: "uint256"
10814
+ }
10815
+ ]
10816
+ },
10817
+ {
10818
+ type: "function",
10819
+ name: "getUserRelayers",
10820
+ constant: true,
10821
+ stateMutability: "view",
10822
+ payable: false,
10823
+ inputs: [
10824
+ {
10825
+ type: "address",
10826
+ name: "account"
10827
+ }
10828
+ ],
10829
+ outputs: [
10830
+ {
10831
+ type: "address[]"
10832
+ }
10833
+ ]
10834
+ },
10835
+ {
10836
+ type: "function",
10837
+ name: "initialize",
10838
+ constant: false,
10839
+ payable: false,
10840
+ inputs: [
10841
+ {
10842
+ type: "address",
10843
+ name: "addressManager"
10844
+ },
10845
+ {
10846
+ type: "address",
10847
+ name: "_feeToken"
10848
+ },
10849
+ {
10850
+ type: "uint256",
10851
+ name: "_relayFee"
10852
+ },
10853
+ {
10854
+ type: "uint256",
10855
+ name: "_relayGas"
10856
+ },
10857
+ {
10858
+ type: "uint256",
10859
+ name: "_maxRelayFee"
10860
+ }
10861
+ ],
10862
+ outputs: []
10863
+ },
10864
+ {
10865
+ type: "function",
10866
+ name: "isTrustedForwarder",
10867
+ constant: true,
10868
+ stateMutability: "view",
10869
+ payable: false,
10870
+ inputs: [
10871
+ {
10872
+ type: "address",
10873
+ name: "forwarder"
10874
+ }
10875
+ ],
10876
+ outputs: [
10877
+ {
10878
+ type: "bool"
10879
+ }
10880
+ ]
10881
+ },
10882
+ {
10883
+ type: "function",
10884
+ name: "isUserRelayerEnabled",
10885
+ constant: true,
10886
+ stateMutability: "view",
10887
+ payable: false,
10888
+ inputs: [
10889
+ {
10890
+ type: "address",
10891
+ name: "account"
10892
+ },
10893
+ {
10894
+ type: "address",
10895
+ name: "relayer"
10896
+ }
10897
+ ],
10898
+ outputs: [
10899
+ {
10900
+ type: "bool"
10901
+ }
10902
+ ]
10903
+ },
10904
+ {
10905
+ type: "function",
10906
+ name: "maxRelayFee",
10907
+ constant: true,
10908
+ stateMutability: "view",
10909
+ payable: false,
10910
+ inputs: [],
10911
+ outputs: [
10912
+ {
10913
+ type: "uint256"
10914
+ }
10915
+ ]
10916
+ },
10917
+ {
10918
+ type: "function",
10919
+ name: "nonces",
10920
+ constant: true,
10921
+ stateMutability: "view",
10922
+ payable: false,
10923
+ inputs: [
10924
+ {
10925
+ type: "address",
10926
+ name: "owner"
10927
+ }
10928
+ ],
10929
+ outputs: [
10930
+ {
10931
+ type: "uint256"
10932
+ }
10933
+ ]
10934
+ },
10935
+ {
10936
+ type: "function",
10937
+ name: "originAccount",
10938
+ constant: true,
10939
+ stateMutability: "view",
10940
+ payable: false,
10941
+ inputs: [
10942
+ {
10943
+ type: "address",
10944
+ name: "relayer"
10945
+ }
10946
+ ],
10947
+ outputs: [
10948
+ {
10949
+ type: "address",
10950
+ name: "account"
10951
+ }
10952
+ ]
10953
+ },
10954
+ {
10955
+ type: "function",
10956
+ name: "permitAndApproveForwarder",
10957
+ constant: false,
10958
+ payable: false,
10959
+ inputs: [
10960
+ {
10961
+ type: "address",
10962
+ name: "relayer"
10963
+ },
10964
+ {
10965
+ type: "bool",
10966
+ name: "enable"
10967
+ },
10968
+ {
10969
+ type: "tuple[]",
10970
+ name: "permitParams",
10971
+ components: [
10972
+ {
10973
+ type: "address",
10974
+ name: "token"
10975
+ },
10976
+ {
10977
+ type: "address",
10978
+ name: "owner"
10979
+ },
10980
+ {
10981
+ type: "address",
10982
+ name: "spender"
10983
+ },
10984
+ {
10985
+ type: "uint256",
10986
+ name: "value"
10987
+ },
10988
+ {
10989
+ type: "uint256",
10990
+ name: "deadline"
10991
+ },
10992
+ {
10993
+ type: "uint8",
10994
+ name: "v"
10995
+ },
10996
+ {
10997
+ type: "bytes32",
10998
+ name: "r"
10999
+ },
11000
+ {
11001
+ type: "bytes32",
11002
+ name: "s"
11003
+ }
11004
+ ]
11005
+ }
11006
+ ],
11007
+ outputs: []
11008
+ },
11009
+ {
11010
+ type: "function",
11011
+ name: "proxiableUUID",
11012
+ constant: true,
11013
+ stateMutability: "view",
11014
+ payable: false,
11015
+ inputs: [],
11016
+ outputs: [
11017
+ {
11018
+ type: "bytes32"
11019
+ }
11020
+ ]
11021
+ },
11022
+ {
11023
+ type: "function",
11024
+ name: "relayFee",
11025
+ constant: true,
11026
+ stateMutability: "view",
11027
+ payable: false,
11028
+ inputs: [],
11029
+ outputs: [
11030
+ {
11031
+ type: "uint256"
11032
+ }
11033
+ ]
11034
+ },
11035
+ {
11036
+ type: "function",
11037
+ name: "relayGas",
11038
+ constant: true,
11039
+ stateMutability: "view",
11040
+ payable: false,
11041
+ inputs: [],
11042
+ outputs: [
11043
+ {
11044
+ type: "uint256"
11045
+ }
11046
+ ]
11047
+ },
11048
+ {
11049
+ type: "function",
11050
+ name: "removeAllowedTarget",
11051
+ constant: false,
11052
+ payable: false,
11053
+ inputs: [
11054
+ {
11055
+ type: "address",
11056
+ name: "target"
11057
+ }
11058
+ ],
11059
+ outputs: []
11060
+ },
11061
+ {
11062
+ type: "function",
11063
+ name: "trustedForwarder",
11064
+ constant: true,
11065
+ stateMutability: "view",
11066
+ payable: false,
11067
+ inputs: [],
11068
+ outputs: [
11069
+ {
11070
+ type: "address"
11071
+ }
11072
+ ]
11073
+ },
11074
+ {
11075
+ type: "function",
11076
+ name: "updateMaxRelayFee",
11077
+ constant: false,
11078
+ payable: false,
11079
+ inputs: [
11080
+ {
11081
+ type: "uint256",
11082
+ name: "_maxRelayFee"
9871
11083
  }
9872
11084
  ],
9873
- outputs: [
9874
- {
9875
- type: "int256",
9876
- name: "netCollateral"
9877
- },
11085
+ outputs: []
11086
+ },
11087
+ {
11088
+ type: "function",
11089
+ name: "updateRelayInfo",
11090
+ constant: false,
11091
+ payable: false,
11092
+ inputs: [
9878
11093
  {
9879
11094
  type: "uint256",
9880
- name: "collateralAmount"
11095
+ name: "_relayFee"
9881
11096
  },
9882
11097
  {
9883
11098
  type: "uint256",
9884
- name: "tradingFee"
11099
+ name: "_relayGas"
11100
+ }
11101
+ ],
11102
+ outputs: []
11103
+ },
11104
+ {
11105
+ type: "function",
11106
+ name: "upgradeTo",
11107
+ constant: false,
11108
+ stateMutability: "payable",
11109
+ payable: true,
11110
+ inputs: [
11111
+ {
11112
+ type: "address",
11113
+ name: "newImplementation"
9885
11114
  },
9886
11115
  {
9887
- type: "int256",
9888
- name: "fundingFee"
11116
+ type: "bytes",
11117
+ name: "data"
9889
11118
  }
9890
- ]
11119
+ ],
11120
+ outputs: []
9891
11121
  },
9892
11122
  {
9893
11123
  type: "function",
9894
- name: "getUserPositionInfos",
9895
- constant: true,
9896
- stateMutability: "view",
9897
- payable: false,
11124
+ name: "upgradeToAndCall",
11125
+ constant: false,
11126
+ stateMutability: "payable",
11127
+ payable: true,
9898
11128
  inputs: [
9899
11129
  {
9900
11130
  type: "address",
9901
- name: "user"
11131
+ name: "newImplementation"
9902
11132
  },
9903
11133
  {
9904
- type: "bytes32[]",
9905
- name: "poolIds"
11134
+ type: "bytes",
11135
+ name: "data"
9906
11136
  }
9907
11137
  ],
9908
- outputs: [
11138
+ outputs: []
11139
+ },
11140
+ {
11141
+ type: "function",
11142
+ name: "verify",
11143
+ constant: true,
11144
+ stateMutability: "view",
11145
+ payable: false,
11146
+ inputs: [
9909
11147
  {
9910
- type: "tuple[]",
9911
- name: "positions",
11148
+ type: "tuple",
11149
+ name: "request",
9912
11150
  components: [
9913
11151
  {
9914
- type: "bytes32",
9915
- name: "positionId"
9916
- },
9917
- {
9918
- type: "bytes32",
9919
- name: "poolId"
11152
+ type: "address",
11153
+ name: "from"
9920
11154
  },
9921
11155
  {
9922
- type: "uint256",
9923
- name: "size"
11156
+ type: "address",
11157
+ name: "to"
9924
11158
  },
9925
11159
  {
9926
11160
  type: "uint256",
9927
- name: "entryPrice"
9928
- },
9929
- {
9930
- type: "int256",
9931
- name: "fundingRateIndex"
11161
+ name: "value"
9932
11162
  },
9933
11163
  {
9934
11164
  type: "uint256",
9935
- name: "earlyClosePrice"
9936
- },
9937
- {
9938
- type: "uint8",
9939
- name: "direction"
11165
+ name: "gas"
9940
11166
  },
9941
11167
  {
9942
- type: "uint8",
9943
- name: "riskTier"
11168
+ type: "uint48",
11169
+ name: "deadline"
9944
11170
  },
9945
11171
  {
9946
- type: "uint64",
9947
- name: "lastUpdateTime"
11172
+ type: "bytes",
11173
+ name: "data"
9948
11174
  },
9949
11175
  {
9950
- type: "uint256",
9951
- name: "collateralAmount"
11176
+ type: "bytes",
11177
+ name: "signature"
9952
11178
  }
9953
11179
  ]
9954
11180
  }
11181
+ ],
11182
+ outputs: [
11183
+ {
11184
+ type: "bool"
11185
+ }
9955
11186
  ]
9956
11187
  }
9957
11188
  ];
@@ -10024,6 +11255,12 @@ var getDataProviderContract = async (chainId, type = 0 /* JSON */) => {
10024
11255
  const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
10025
11256
  return getContract(address, DataProvider_default, provider);
10026
11257
  };
11258
+ var getForwarderContract = async (chainId, type = 0 /* JSON */) => {
11259
+ const addresses = address_default[chainId];
11260
+ const address = addresses.FORWARDER;
11261
+ const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
11262
+ return getContract(address, Forwarder_default, provider);
11263
+ };
10027
11264
 
10028
11265
  // src/config/error.ts
10029
11266
  import { ErrorType, ErrorDecoder } from "ethers-decode-error";
@@ -13118,30 +14355,6 @@ var Order = class {
13118
14355
  useAccountBalance: false
13119
14356
  };
13120
14357
  });
13121
- const gasLimittest = await brokerContract.placeOrdersWithPosition.estimateGas(["0x8d11a77fc9225f16955c717b40ea826befc1703a4b6810b30093af4860085b8f"], [{
13122
- user: "0x0F5A0a5F807A76244897A93aa8FE9121E7df15cf",
13123
- poolId: "0x0f3a23ce1f81d792bb74b7e748d7ee0c0c459db3c5fd06e1c792935f9a90fce0",
13124
- orderType: 0,
13125
- triggerType: 0,
13126
- operation: 1,
13127
- direction: 0,
13128
- collateralAmount: 1000000n,
13129
- size: "1000000000000000000",
13130
- price: "87711469284207055000000000000000000",
13131
- timeInForce: TIME_IN_FORCE,
13132
- postOnly: false,
13133
- slippagePct: 1e3,
13134
- executionFeeToken: "0x7e248ec1721639413a280d9e82e2862cae2e6e28",
13135
- leverage: 10,
13136
- tpSize: 0,
13137
- tpPrice: 0,
13138
- slSize: 0,
13139
- slPrice: 0,
13140
- useAccountBalance: false
13141
- }]);
13142
- console.log("gasLimittest--->", gasLimittest);
13143
- this.logger.info("closeAllPositions positionIds--->", positionIds);
13144
- this.logger.info("closeAllPositions dataMap--->", dataMap);
13145
14358
  const gasLimit = await brokerContract.placeOrdersWithPosition.estimateGas(positionIds, dataMap);
13146
14359
  const transaction = await brokerContract.placeOrdersWithPosition(positionIds, dataMap, {
13147
14360
  gasLimit: gasLimit * 120n / 100n
@@ -19051,6 +20264,470 @@ var Account = class {
19051
20264
  }
19052
20265
  };
19053
20266
 
20267
+ // src/manager/seamless/index.ts
20268
+ import CryptoJS from "crypto-js";
20269
+ import { toUtf8Bytes, keccak256 as keccak2562, hexlify, ethers as ethers9, isHexString, getBytes, ZeroAddress as ZeroAddress2 } from "ethers";
20270
+ import dayjs from "dayjs";
20271
+
20272
+ // src/utils/index.ts
20273
+ function getChainDomainConfig(chainId, address) {
20274
+ return CHAIN_DOMAIN?.[chainId]?.[address];
20275
+ }
20276
+ var CHAIN_DOMAIN = {
20277
+ [421614 /* ARB_TESTNET */]: {
20278
+ [getContractAddressByChainId(421614 /* ARB_TESTNET */).USDC]: {
20279
+ name: "USDC",
20280
+ version: "2",
20281
+ chainId: 421614 /* ARB_TESTNET */.toString(),
20282
+ verifyingContract: getContractAddressByChainId(421614 /* ARB_TESTNET */).USDC
20283
+ }
20284
+ }
20285
+ };
20286
+ var getEIP712Domain = async (contract) => {
20287
+ try {
20288
+ const eip712Domain = await contract.eip712Domain();
20289
+ return {
20290
+ name: eip712Domain.name,
20291
+ version: eip712Domain.version,
20292
+ chainId: BigInt(eip712Domain.chainId),
20293
+ // 确保 chainId 是ForwarderGetStatus bigint 类型
20294
+ verifyingContract: eip712Domain.verifyingContract
20295
+ };
20296
+ } catch (error) {
20297
+ throw new Error(`Error fetching EIP712 domain: ${error}`);
20298
+ }
20299
+ };
20300
+ function wait(ms) {
20301
+ return new Promise((resolve) => setTimeout(resolve, ms));
20302
+ }
20303
+ function waitRandom(min, max) {
20304
+ return wait(min + Math.round(Math.random() * Math.max(0, max - min)));
20305
+ }
20306
+ var CanceledError = class extends Error {
20307
+ constructor() {
20308
+ super();
20309
+ this.name = "CanceledError";
20310
+ this.message = "Retryable was canceled";
20311
+ this.name = "CanceledError";
20312
+ }
20313
+ };
20314
+ var RetryableError = class extends Error {
20315
+ constructor() {
20316
+ super();
20317
+ this.name = "RetryableError";
20318
+ this.name = "RetryableError";
20319
+ }
20320
+ };
20321
+ var TimeoutError = class extends Error {
20322
+ constructor() {
20323
+ super();
20324
+ this.name = "TimeoutError";
20325
+ this.message = "Retryable was Timeout";
20326
+ this.name = "TimeoutError";
20327
+ }
20328
+ };
20329
+ function retry(fn, { n, minWait, maxWait }) {
20330
+ let completed = false;
20331
+ let rejectCancelled;
20332
+ const promise = new Promise(async (resolve, reject) => {
20333
+ rejectCancelled = reject;
20334
+ while (true) {
20335
+ let result;
20336
+ try {
20337
+ result = await fn();
20338
+ if (!completed) {
20339
+ resolve(result);
20340
+ completed = true;
20341
+ }
20342
+ break;
20343
+ } catch (error) {
20344
+ if (completed) {
20345
+ break;
20346
+ }
20347
+ if (n <= 0 || !(error instanceof RetryableError)) {
20348
+ if (error instanceof RetryableError) {
20349
+ reject(new TimeoutError());
20350
+ } else {
20351
+ reject(error);
20352
+ }
20353
+ completed = true;
20354
+ break;
20355
+ }
20356
+ n--;
20357
+ }
20358
+ await waitRandom(minWait, maxWait);
20359
+ }
20360
+ });
20361
+ return {
20362
+ promise,
20363
+ cancel: () => {
20364
+ if (completed) return;
20365
+ completed = true;
20366
+ rejectCancelled(new CanceledError());
20367
+ }
20368
+ };
20369
+ }
20370
+
20371
+ // src/manager/seamless/index.ts
20372
+ import { splitSignature } from "@ethersproject/bytes";
20373
+ var contractTypes = {
20374
+ ForwardRequest: [
20375
+ { name: "from", type: "address" },
20376
+ { name: "to", type: "address" },
20377
+ { name: "value", type: "uint256" },
20378
+ { name: "gas", type: "uint256" },
20379
+ { name: "nonce", type: "uint256" },
20380
+ { name: "deadline", type: "uint48" },
20381
+ { name: "data", type: "bytes" }
20382
+ ]
20383
+ };
20384
+ var FORWARD_PLEDGE_FEE_RADIO = 2;
20385
+ var calculateSignature = async (message) => {
20386
+ const encoder = new TextEncoder();
20387
+ const data = encoder.encode(message);
20388
+ const hashBuffer = await window.crypto.subtle.digest("SHA-256", data);
20389
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
20390
+ return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
20391
+ };
20392
+ var seamlessNonceString = "jAkBlC4~5!6@#$%^";
20393
+ var generateEthWalletFromHashedSignature = (hashedSignature) => {
20394
+ const seedStringToUtf8Bytes = toUtf8Bytes(hashedSignature);
20395
+ const seedStringToKeccak256 = keccak2562(seedStringToUtf8Bytes);
20396
+ const seedStringToKeccak256Array = getBytes(seedStringToKeccak256);
20397
+ const privateKey = hexlify(seedStringToKeccak256Array);
20398
+ if (!isHexString(privateKey, 32)) {
20399
+ throw new MyxSDKError("INVALID_PRIVATE_KEY" /* InvalidPrivateKey */, "Invalid private key generated");
20400
+ }
20401
+ const wallet = new ethers9.Wallet(privateKey);
20402
+ return {
20403
+ privateKey,
20404
+ wallet
20405
+ };
20406
+ };
20407
+ var charFill = (ping) => {
20408
+ const targetLength = 16;
20409
+ if (ping.length >= targetLength) {
20410
+ return ping;
20411
+ }
20412
+ const remainingLength = targetLength - ping.length;
20413
+ const repeatTimes = Math.ceil(remainingLength / ping.length);
20414
+ const paddedString = ping.repeat(repeatTimes).slice(0, remainingLength);
20415
+ return ping + paddedString;
20416
+ };
20417
+ var getIvMapString = () => CryptoJS.enc.Utf8.parse(seamlessNonceString);
20418
+ async function signPermit(provider, contract, owner, spender, value, nonce, deadline, chainId) {
20419
+ const chainDomainConfig = getChainDomainConfig(chainId, contract.target);
20420
+ const domain = chainDomainConfig ?? await getEIP712Domain(contract);
20421
+ const types = {
20422
+ Permit: [
20423
+ { name: "owner", type: "address" },
20424
+ { name: "spender", type: "address" },
20425
+ { name: "value", type: "uint256" },
20426
+ { name: "nonce", type: "uint256" },
20427
+ { name: "deadline", type: "uint256" }
20428
+ ]
20429
+ };
20430
+ const message = {
20431
+ owner,
20432
+ spender,
20433
+ value,
20434
+ nonce,
20435
+ deadline
20436
+ };
20437
+ const signature = await provider.signTypedData(domain, types, message);
20438
+ const { v, r, s } = splitSignature(signature);
20439
+ return { v, r, s };
20440
+ }
20441
+ var Seamless = class {
20442
+ constructor(configManager, logger, utils, account) {
20443
+ this.configManager = configManager;
20444
+ this.logger = logger;
20445
+ this.utils = utils;
20446
+ this.account = account;
20447
+ this.seamlessWallet = null;
20448
+ this.seamlessWalletAuthorized = false;
20449
+ this.seamlessWalletApikey = "";
20450
+ }
20451
+ async onCheckRelayer(account, relayer) {
20452
+ const config = this.configManager.getConfig();
20453
+ const forwarderContract = await getForwarderContract(config.chainId);
20454
+ const checkRelayerResult = await forwarderContract.isUserRelayerEnabled(account, relayer);
20455
+ console.log("checkRelayerResult-->", checkRelayerResult);
20456
+ return checkRelayerResult;
20457
+ }
20458
+ async getUSDPermitParams(deadline) {
20459
+ const config = this.configManager.getConfig();
20460
+ const chainId = config.chainId;
20461
+ const masterAddress = config.signer?.getAddress();
20462
+ const brokerAddress = config.brokerAddress;
20463
+ const contractAddress = getContractAddressByChainId(config.chainId);
20464
+ const erc20Contract = new ethers9.Contract(
20465
+ contractAddress.ERC20,
20466
+ ERC20Token_default,
20467
+ config.signer
20468
+ );
20469
+ const walletProvider = await getWalletProvider(chainId);
20470
+ try {
20471
+ const nonces = await erc20Contract.nonces(masterAddress);
20472
+ const brokerSignPermit = await signPermit(
20473
+ // @ts-ignore
20474
+ walletProvider,
20475
+ erc20Contract,
20476
+ masterAddress,
20477
+ brokerAddress,
20478
+ ethers9.MaxUint256,
20479
+ nonces,
20480
+ deadline.toString(),
20481
+ chainId
20482
+ );
20483
+ const brokerSeamlessUSDPermitParams = {
20484
+ token: erc20Contract.target,
20485
+ owner: masterAddress,
20486
+ spender: brokerAddress,
20487
+ value: ethers9.MaxUint256,
20488
+ deadline,
20489
+ v: brokerSignPermit.v,
20490
+ r: brokerSignPermit.r,
20491
+ s: brokerSignPermit.s
20492
+ };
20493
+ return [brokerSeamlessUSDPermitParams];
20494
+ } catch (error) {
20495
+ throw new MyxSDKError("INVALID_PRIVATE_KEY" /* InvalidPrivateKey */, "Invalid private key generated");
20496
+ }
20497
+ return;
20498
+ }
20499
+ async forwarderTx({
20500
+ from,
20501
+ to,
20502
+ value,
20503
+ gas,
20504
+ deadline,
20505
+ data,
20506
+ nonce
20507
+ }) {
20508
+ const config = this.configManager.getConfig();
20509
+ const forwarderContract = await getForwarderContract(config.chainId);
20510
+ const forwarderJsonRpcContractDomain = await forwarderContract.eip712Domain();
20511
+ const domain = {
20512
+ name: forwarderJsonRpcContractDomain.name,
20513
+ version: forwarderJsonRpcContractDomain.version,
20514
+ chainId: forwarderJsonRpcContractDomain.chainId,
20515
+ verifyingContract: forwarderJsonRpcContractDomain.verifyingContract
20516
+ };
20517
+ const walletProvider = await getSignerProvider(config.chainId);
20518
+ const signature = await walletProvider.signTypedData(domain, contractTypes, {
20519
+ from,
20520
+ to,
20521
+ value,
20522
+ gas,
20523
+ nonce,
20524
+ deadline,
20525
+ data
20526
+ });
20527
+ const txRs = await forwarderTxApi({ from, to, value, gas, nonce, data, deadline, signature }, config.chainId);
20528
+ return txRs;
20529
+ }
20530
+ async authorizeSeamlessAccount({ approve: approve2, seamlessAddress }) {
20531
+ console.log("authorizeSeamlessAccount-->", approve2, seamlessAddress);
20532
+ const config = this.configManager.getConfig();
20533
+ const accessToken = await this.configManager.getAccessToken();
20534
+ if (!accessToken) {
20535
+ throw new MyxSDKError("INVALID_ACCESS_TOKEN" /* InvalidAccessToken */, "Invalid access token");
20536
+ }
20537
+ const masterAddress = await config.signer?.getAddress() ?? "";
20538
+ if (approve2) {
20539
+ const balanceRes = await this.account.getWalletQuoteTokenBalance();
20540
+ const balance = balanceRes.data;
20541
+ const forwarderContract2 = await getForwarderContract(config.chainId);
20542
+ const pledgeFee = await forwarderContract2.getRelayFee();
20543
+ const gasFee = BigInt(pledgeFee) * BigInt(FORWARD_PLEDGE_FEE_RADIO);
20544
+ if (gasFee > 0 && gasFee > BigInt(balance)) {
20545
+ throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient balance");
20546
+ }
20547
+ }
20548
+ const deadline = dayjs().add(60, "minute").unix();
20549
+ let permitParams = [];
20550
+ if (approve2) {
20551
+ try {
20552
+ permitParams = await this.getUSDPermitParams(deadline);
20553
+ } catch (error) {
20554
+ console.warn("Failed to get USD permit params, proceeding without permit:", error);
20555
+ permitParams = [];
20556
+ }
20557
+ }
20558
+ const forwarderContract = await getForwarderContract(config.chainId);
20559
+ const nonce = await forwarderContract.nonces(masterAddress);
20560
+ const gasLimit = SEAMLESS_ACCOUNT_GAS_LIMIT;
20561
+ const provider = await getJSONProvider(config.chainId);
20562
+ const { gasPrice } = await provider.getFeeData();
20563
+ const gas = BigInt(gasLimit) * BigInt(120) * BigInt(gasPrice ?? 0) / BigInt(100);
20564
+ const functionHash = forwarderContract.interface.encodeFunctionData("permitAndApproveForwarder", [
20565
+ seamlessAddress,
20566
+ approve2,
20567
+ permitParams
20568
+ ]);
20569
+ const txRs = await this.forwarderTx({
20570
+ from: masterAddress ?? "",
20571
+ to: forwarderContract?.target,
20572
+ value: "0",
20573
+ gas: "350000",
20574
+ //gas.toString(),
20575
+ nonce: nonce.toString(),
20576
+ data: functionHash,
20577
+ deadline
20578
+ });
20579
+ if (!txRs.data?.txHash) {
20580
+ const retryOptions = { n: 10, minWait: 250, maxWait: 1e3 };
20581
+ const { promise } = retry(async () => {
20582
+ const getRs = await fetchForwarderGetApi({
20583
+ requestId: txRs.data?.requestId
20584
+ });
20585
+ this.logger.info("authorizeSeamlessAccount result-->", getRs);
20586
+ if (getRs.data?.status === 9 /* EXECUTED */) {
20587
+ if (getRs.data?.txHash) {
20588
+ txRs.data.txHash = getRs.data.txHash;
20589
+ return {
20590
+ code: 0,
20591
+ data: {
20592
+ seamlessAccount: seamlessAddress,
20593
+ authorized: approve2
20594
+ }
20595
+ };
20596
+ } else {
20597
+ throw new MyxSDKError("OPERATION_FAILED" /* OperationFailed */, "Operation failed, please try again later");
20598
+ }
20599
+ } else if ([2 /* BROADCAST_FAILED */, 3 /* TIMEOUT_CANCEL */].includes(getRs?.data?.status)) {
20600
+ throw new MyxSDKError("OPERATION_FAILED" /* OperationFailed */, "Operation failed, please try again later");
20601
+ }
20602
+ throw new RetryableError();
20603
+ }, retryOptions);
20604
+ try {
20605
+ await promise;
20606
+ } catch (err) {
20607
+ if (err instanceof TimeoutError) {
20608
+ throw new MyxSDKError("TIMEOUT" /* Timeout */, "Your request timed out, please try again");
20609
+ } else {
20610
+ throw err;
20611
+ }
20612
+ }
20613
+ }
20614
+ }
20615
+ async unLockSeamlessWallet({ masterAddress, password, apiKey }) {
20616
+ const key = CryptoJS.enc.Utf8.parse(charFill(password));
20617
+ const iv = getIvMapString();
20618
+ const decrypted = CryptoJS.AES.decrypt(apiKey, key, {
20619
+ iv,
20620
+ mode: CryptoJS.mode.CBC,
20621
+ padding: CryptoJS.pad.Pkcs7
20622
+ });
20623
+ const privateKey = decrypted.toString(CryptoJS.enc.Utf8);
20624
+ const wallet = new ethers9.Wallet(privateKey);
20625
+ this.seamlessWallet = wallet;
20626
+ const isAuthorized = await this.onCheckRelayer(masterAddress, wallet.address);
20627
+ this.seamlessWalletAuthorized = isAuthorized;
20628
+ return {
20629
+ code: 0,
20630
+ data: {
20631
+ masterAddress,
20632
+ seamlessAccount: wallet.address,
20633
+ authorized: isAuthorized
20634
+ }
20635
+ };
20636
+ }
20637
+ async exportSeamlessPrivateKey({ password, apiKey }) {
20638
+ const key = CryptoJS.enc.Utf8.parse(charFill(password));
20639
+ const iv = getIvMapString();
20640
+ const decrypted = CryptoJS.AES.decrypt(apiKey, key, {
20641
+ iv,
20642
+ mode: CryptoJS.mode.CBC,
20643
+ padding: CryptoJS.pad.Pkcs7
20644
+ });
20645
+ const privateKey = decrypted.toString(CryptoJS.enc.Utf8);
20646
+ const wallet = new ethers9.Wallet(privateKey);
20647
+ if (wallet.address !== this.seamlessWallet?.address) {
20648
+ throw new MyxSDKError("INVALID_PRIVATE_KEY" /* InvalidPrivateKey */, "Invalid private key");
20649
+ }
20650
+ return {
20651
+ code: 0,
20652
+ data: {
20653
+ privateKey
20654
+ }
20655
+ };
20656
+ }
20657
+ async importSeamlessPrivateKey({ privateKey, password }) {
20658
+ const config = this.configManager.getConfig();
20659
+ if (!ethers9.isHexString(privateKey, 32)) {
20660
+ throw new MyxSDKError("INVALID_PRIVATE_KEY" /* InvalidPrivateKey */, "Invalid private key");
20661
+ }
20662
+ const wallet = new ethers9.Wallet(privateKey);
20663
+ const forwarderContract = await getForwarderContract(config.chainId);
20664
+ const masterAddress = await forwarderContract.originAccount(wallet.address);
20665
+ if (masterAddress === ZeroAddress2) {
20666
+ throw new MyxSDKError("INVALID_PRIVATE_KEY" /* InvalidPrivateKey */, "The private key is not a senseless account");
20667
+ }
20668
+ const isAuthorized = await this.onCheckRelayer(masterAddress, wallet.address);
20669
+ const key = CryptoJS.enc.Utf8.parse(charFill(password));
20670
+ const iv = getIvMapString();
20671
+ const encrypted = CryptoJS.AES.encrypt(privateKey, key, {
20672
+ iv,
20673
+ mode: CryptoJS.mode.CBC,
20674
+ padding: CryptoJS.pad.Pkcs7
20675
+ });
20676
+ const apiKey = encrypted.toString();
20677
+ this.seamlessWallet = wallet;
20678
+ this.seamlessWalletAuthorized = isAuthorized;
20679
+ this.seamlessWalletApikey = apiKey;
20680
+ return {
20681
+ code: 0,
20682
+ data: {
20683
+ masterAddress,
20684
+ seamlessAccount: wallet.address,
20685
+ authorized: isAuthorized,
20686
+ apiKey
20687
+ }
20688
+ };
20689
+ }
20690
+ async createSeamless({ password }) {
20691
+ const config = this.configManager.getConfig();
20692
+ const signer = config.signer;
20693
+ const account = await signer?.getAddress() ?? "";
20694
+ if (!signer) {
20695
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
20696
+ }
20697
+ try {
20698
+ const createAccountSignature = await signer.signMessage(`${account}_${password}`);
20699
+ const hashedSignature = await calculateSignature(createAccountSignature);
20700
+ const { privateKey, wallet } = generateEthWalletFromHashedSignature(hashedSignature);
20701
+ const key = CryptoJS.enc.Utf8.parse(charFill(password));
20702
+ const iv = getIvMapString();
20703
+ const encrypted = CryptoJS.AES.encrypt(privateKey, key, {
20704
+ iv,
20705
+ mode: CryptoJS.mode.CBC,
20706
+ padding: CryptoJS.pad.Pkcs7
20707
+ });
20708
+ const apiKey = encrypted.toString();
20709
+ const isAuthorized = await this.onCheckRelayer(account, wallet.address);
20710
+ this.seamlessWallet = wallet;
20711
+ this.seamlessWalletAuthorized = isAuthorized;
20712
+ this.seamlessWalletApikey = apiKey;
20713
+ return {
20714
+ code: 0,
20715
+ data: {
20716
+ masterAddress: account,
20717
+ seamlessAccount: wallet.address,
20718
+ authorized: isAuthorized,
20719
+ apiKey
20720
+ }
20721
+ };
20722
+ } catch (error) {
20723
+ return {
20724
+ code: -1,
20725
+ message: error.message
20726
+ };
20727
+ }
20728
+ }
20729
+ };
20730
+
19054
20731
  // src/manager/index.ts
19055
20732
  var MyxClient = class {
19056
20733
  /**
@@ -19070,6 +20747,7 @@ var MyxClient = class {
19070
20747
  this.position = new Position(this.configManager, this.logger, this.utils);
19071
20748
  this.order = new Order(this.configManager, this.logger, this.utils, this.account);
19072
20749
  this.subscription = new SubScription(this.configManager, this.logger);
20750
+ this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
19073
20751
  const lp = MxSDK.getInstance();
19074
20752
  lp.setConfigManager(this.configManager);
19075
20753
  }
@@ -19102,6 +20780,7 @@ export {
19102
20780
  DirectionEnum,
19103
20781
  ErrorCode,
19104
20782
  ExecTypeEnum,
20783
+ ForwarderGetStatus,
19105
20784
  HttpKlineIntervalEnum,
19106
20785
  MarketCapType,
19107
20786
  MarketPoolState,
@@ -19126,7 +20805,10 @@ export {
19126
20805
  bigintAmountSlipperCalculator,
19127
20806
  bigintTradingGasPriceWithRatio,
19128
20807
  bigintTradingGasToRatioCalculator,
20808
+ fetchForwarderGetApi,
19129
20809
  formatUnits2 as formatUnits,
20810
+ forwardUrl,
20811
+ forwarderTxApi,
19130
20812
  getAllTickers,
19131
20813
  getAllowanceApproved,
19132
20814
  getBalanceOf,