@xyo-network/chain-bridge 1.20.8 → 1.20.9
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/node/index.mjs +144 -72
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.d.ts +77 -0
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.d.ts.map +1 -0
- package/dist/node/server/routes/bridge/routeDefinitions/routes/index.d.ts +1 -0
- package/dist/node/server/routes/bridge/routeDefinitions/routes/index.d.ts.map +1 -1
- package/dist/node/util/calculateMaxBridgeAmount.d.ts +11 -0
- package/dist/node/util/calculateMaxBridgeAmount.d.ts.map +1 -0
- package/dist/node/util/index.d.ts +1 -0
- package/dist/node/util/index.d.ts.map +1 -1
- package/dist/node/validation/validateBridgeEstimateExact.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts +2 -1
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +11 -2
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.ts +64 -0
- package/src/server/routes/bridge/routeDefinitions/routes/index.ts +1 -0
- package/src/util/calculateMaxBridgeAmount.ts +22 -0
- package/src/util/index.ts +1 -0
- package/src/validation/validateBridgeEstimateExact.ts +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRouteDefinitions.d.ts","sourceRoot":"","sources":["../../../../../../src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAM5D,eAAO,MAAM,mBAAmB,GAAI,QAAQ,YAAY,EAAE,SAAS,gBAAgB,KAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"getRouteDefinitions.d.ts","sourceRoot":"","sources":["../../../../../../src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAM5D,eAAO,MAAM,mBAAmB,GAAI,QAAQ,YAAY,EAAE,SAAS,gBAAgB,KAAG,eAAe,EASpG,CAAA"}
|
package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridgeToRemoteEstimate.d.ts","sourceRoot":"","sources":["../../../../../../../src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"bridgeToRemoteEstimate.d.ts","sourceRoot":"","sources":["../../../../../../../src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAKtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAI5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,6BAA6B;;;;iBAIxC,CAAA;AACF,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA;AAEtF,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAI5C,CAAA;AAEF,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAAC,CAAA;AAE9F,eAAO,MAAM,+BAA+B,GAAI,QAAQ,YAAY,EAAE,SAAS,gBAAgB,KAAG,eAoCjG,CAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { RouteDefinition } from '@xylabs/express';
|
|
2
|
+
import type { BridgeConfig } from '@xyo-network/chain-orchestration';
|
|
3
|
+
import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare const BridgeToRemoteMaxEstimateBodyZod: z.ZodObject<{
|
|
6
|
+
srcAmount: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
7
|
+
srcAddress: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
8
|
+
destAddress: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export type BridgeToRemoteMaxEstimateBody = z.infer<typeof BridgeToRemoteMaxEstimateBodyZod>;
|
|
11
|
+
export declare const BridgeToRemoteMaxEstimateResponseZod: z.ZodTuple<[z.ZodObject<{
|
|
12
|
+
schema: z.ZodLiteral<"network.xyo.boundwitness" & {
|
|
13
|
+
readonly __schema: true;
|
|
14
|
+
}>;
|
|
15
|
+
addresses: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & {
|
|
16
|
+
readonly __hex: true;
|
|
17
|
+
} & {
|
|
18
|
+
readonly __address: true;
|
|
19
|
+
}, string>>>;
|
|
20
|
+
payload_hashes: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHash, string>>>;
|
|
21
|
+
payload_schemas: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<import("@xyo-network/sdk-js").BrandedSchema<string>, string>>>;
|
|
22
|
+
previous_hashes: z.ZodArray<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHash, string>>>>;
|
|
23
|
+
$destination: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & {
|
|
24
|
+
readonly __hex: true;
|
|
25
|
+
} & {
|
|
26
|
+
readonly __address: true;
|
|
27
|
+
}, string>>>;
|
|
28
|
+
$sourceQuery: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHash, string>>>;
|
|
29
|
+
$signatures: z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>, z.ZodNull]>>;
|
|
30
|
+
nbf: z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-sdk").XL1BlockNumber, number>>;
|
|
31
|
+
exp: z.ZodPipe<z.ZodNumber, z.ZodTransform<import("@xyo-network/xl1-sdk").XL1BlockNumber, number>>;
|
|
32
|
+
fees: z.ZodObject<{
|
|
33
|
+
base: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
34
|
+
gasLimit: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
35
|
+
gasPrice: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
36
|
+
priority: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
chain: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
39
|
+
from: z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & {
|
|
40
|
+
readonly __hex: true;
|
|
41
|
+
} & {
|
|
42
|
+
readonly __address: true;
|
|
43
|
+
}, string>>;
|
|
44
|
+
script: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
45
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
46
|
+
schema: z.ZodLiteral<"network.xyo.chain.bridge.intent" & {
|
|
47
|
+
readonly __schema: true;
|
|
48
|
+
}>;
|
|
49
|
+
src: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
50
|
+
srcAddress: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
51
|
+
srcAmount: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
52
|
+
srcToken: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
53
|
+
dest: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
54
|
+
destAddress: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
55
|
+
destAmount: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
56
|
+
destToken: z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>;
|
|
57
|
+
nonce: z.ZodString;
|
|
58
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
59
|
+
schema: z.ZodLiteral<"network.xyo.transfer" & {
|
|
60
|
+
readonly __schema: true;
|
|
61
|
+
}>;
|
|
62
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
63
|
+
epoch: z.ZodNumber;
|
|
64
|
+
from: z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & {
|
|
65
|
+
readonly __hex: true;
|
|
66
|
+
} & {
|
|
67
|
+
readonly __address: true;
|
|
68
|
+
}, string>>;
|
|
69
|
+
transfers: z.ZodRecord<z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & {
|
|
70
|
+
readonly __hex: true;
|
|
71
|
+
} & {
|
|
72
|
+
readonly __address: true;
|
|
73
|
+
}, string>>, z.ZodPipe<z.ZodString, z.ZodTransform<import("@xylabs/sdk-js").BrandedHex, string>>>;
|
|
74
|
+
}, z.core.$strip>], null>;
|
|
75
|
+
export type BridgeToRemoteMaxEstimateResponse = z.infer<typeof BridgeToRemoteMaxEstimateResponseZod>;
|
|
76
|
+
export declare const makeBridgeToRemoteMaxEstimateRoute: (config: BridgeConfig, gateway: XyoGatewayRunner) => RouteDefinition;
|
|
77
|
+
//# sourceMappingURL=bridgeToRemoteMaxEstimate.d.ts.map
|
package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridgeToRemoteMaxEstimate.d.ts","sourceRoot":"","sources":["../../../../../../../src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAKtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAI5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,gCAAgC;;;;iBAI3C,CAAA;AACF,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AAE5F,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAI/C,CAAA;AAEF,MAAM,MAAM,iCAAiC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oCAAoC,CAAC,CAAA;AAEpG,eAAO,MAAM,kCAAkC,GAAI,QAAQ,YAAY,EAAE,SAAS,gBAAgB,KAAG,eA+BpG,CAAA"}
|
|
@@ -2,5 +2,6 @@ export * from './bridgeConfig.ts';
|
|
|
2
2
|
export * from './bridgeFromRemoteStatus.ts';
|
|
3
3
|
export * from './bridgeToRemote.ts';
|
|
4
4
|
export * from './bridgeToRemoteEstimate.ts';
|
|
5
|
+
export * from './bridgeToRemoteMaxEstimate.ts';
|
|
5
6
|
export * from './bridgeToRemoteStatus.ts';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/server/routes/bridge/routeDefinitions/routes/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/server/routes/bridge/routeDefinitions/routes/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Hex } from '@xylabs/sdk-js';
|
|
2
|
+
import type { FeeStructure } from './calculateBridgeFees.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Given a user's total available balance, calculates the maximum amount they can bridge
|
|
5
|
+
* after accounting for the fixed and variable bridge fees.
|
|
6
|
+
*
|
|
7
|
+
* Solving for M where: M + feeFixed + (M * basisPoints / 10_000) = balance
|
|
8
|
+
* => M = (balance - feeFixed) * 10_000 / (10_000 + basisPoints)
|
|
9
|
+
*/
|
|
10
|
+
export declare const calculateMaxBridgeAmount: (balance: Hex, feeStructure: FeeStructure) => Hex;
|
|
11
|
+
//# sourceMappingURL=calculateMaxBridgeAmount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculateMaxBridgeAmount.d.ts","sourceRoot":"","sources":["../../../src/util/calculateMaxBridgeAmount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAGzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAE5D;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,GAAG,EAAE,cAAc,YAAY,KAAG,GASnF,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './BridgeFees.ts';
|
|
2
2
|
export * from './bridgeFeesAsBigInt.ts';
|
|
3
3
|
export * from './calculateBridgeFees.ts';
|
|
4
|
+
export * from './calculateMaxBridgeAmount.ts';
|
|
4
5
|
export * from './createBridgeTransfer.ts';
|
|
5
6
|
export * from './generateBridgeEstimate.ts';
|
|
6
7
|
export * from './getConfigFromEnv.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AACzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,uBAAuB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateBridgeEstimateExact.d.ts","sourceRoot":"","sources":["../../../src/validation/validateBridgeEstimateExact.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"validateBridgeEstimateExact.d.ts","sourceRoot":"","sources":["../../../src/validation/validateBridgeEstimateExact.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAKlE;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,GACtC,QAAQ,YAAY,EACpB,UAAU,QAAQ,EAClB,QAAQ,YAAY,KACnB,OAAO,CAAC,OAAO,CAkBjB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/chain-bridge",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.9",
|
|
4
4
|
"description": "XYO Layer One Bridge",
|
|
5
5
|
"homepage": "https://xylabs.com",
|
|
6
6
|
"bugs": {
|
|
@@ -49,51 +49,51 @@
|
|
|
49
49
|
"types": "tsc --noEmit -p tsconfig.test.json"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@opentelemetry/api": "^1.9.
|
|
53
|
-
"@opentelemetry/instrumentation": "~0.
|
|
52
|
+
"@opentelemetry/api": "^1.9.1",
|
|
53
|
+
"@opentelemetry/instrumentation": "~0.214.0",
|
|
54
54
|
"@opentelemetry/instrumentation-express": "~0.61.0",
|
|
55
|
-
"@opentelemetry/instrumentation-http": "~0.
|
|
56
|
-
"@xylabs/express": "~5.0.
|
|
57
|
-
"@xylabs/mongo": "~5.0.
|
|
58
|
-
"@xylabs/sdk-js": "~5.0.
|
|
55
|
+
"@opentelemetry/instrumentation-http": "~0.214.0",
|
|
56
|
+
"@xylabs/express": "~5.0.87",
|
|
57
|
+
"@xylabs/mongo": "~5.0.87",
|
|
58
|
+
"@xylabs/sdk-js": "~5.0.87",
|
|
59
59
|
"@xyo-network/boundwitness-validator": "~5.3.16",
|
|
60
|
-
"@xyo-network/chain-orchestration": "~1.20.
|
|
61
|
-
"@xyo-network/chain-protocol": "~1.20.
|
|
62
|
-
"@xyo-network/chain-services": "~1.20.
|
|
60
|
+
"@xyo-network/chain-orchestration": "~1.20.9",
|
|
61
|
+
"@xyo-network/chain-protocol": "~1.20.9",
|
|
62
|
+
"@xyo-network/chain-services": "~1.20.9",
|
|
63
63
|
"@xyo-network/sdk-js": "~5.3.16",
|
|
64
64
|
"@xyo-network/typechain": "~4.1.2",
|
|
65
65
|
"@xyo-network/wallet-model": "~5.3.16",
|
|
66
|
-
"@xyo-network/xl1-sdk": "~1.
|
|
66
|
+
"@xyo-network/xl1-sdk": "~1.26.4",
|
|
67
67
|
"async-mutex": "~0.5.0",
|
|
68
|
-
"bullmq": "~5.71.
|
|
68
|
+
"bullmq": "~5.71.1",
|
|
69
69
|
"bullmq-otel": "~1.3.0",
|
|
70
70
|
"ethers": "^6.16.0",
|
|
71
71
|
"express": "~5.2.1",
|
|
72
|
-
"ioredis": "5.
|
|
73
|
-
"mongodb": "
|
|
72
|
+
"ioredis": "5.10.1",
|
|
73
|
+
"mongodb": "~7.1.1",
|
|
74
74
|
"uuid": "~13.0.0",
|
|
75
75
|
"yargs-parser": "~22.0.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@opentelemetry/api": "^1.9.
|
|
78
|
+
"@opentelemetry/api": "^1.9.1",
|
|
79
79
|
"@types/node": "~25.5.0",
|
|
80
80
|
"@types/yargs-parser": "~21.0.3",
|
|
81
|
-
"@xylabs/mongo": "~5.0.
|
|
82
|
-
"@xylabs/sdk-js": "~5.0.
|
|
83
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
84
|
-
"@xylabs/tsconfig": "~7.4.
|
|
85
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
86
|
-
"@xyo-network/chain-protocol": "~1.20.
|
|
87
|
-
"@xyo-network/chain-services": "~1.20.
|
|
81
|
+
"@xylabs/mongo": "~5.0.87",
|
|
82
|
+
"@xylabs/sdk-js": "~5.0.87",
|
|
83
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.28",
|
|
84
|
+
"@xylabs/tsconfig": "~7.4.28",
|
|
85
|
+
"@xylabs/vitest-extended": "~5.0.87",
|
|
86
|
+
"@xyo-network/chain-protocol": "~1.20.9",
|
|
87
|
+
"@xyo-network/chain-services": "~1.20.9",
|
|
88
88
|
"@xyo-network/chain-test-helpers": "workspace:packages/test-helpers",
|
|
89
89
|
"@xyo-network/sdk-js": "~5.3.16",
|
|
90
|
-
"@xyo-network/xl1-sdk": "~1.
|
|
90
|
+
"@xyo-network/xl1-sdk": "~1.26.4",
|
|
91
91
|
"async-mutex": "~0.5.0",
|
|
92
92
|
"axios": "~1.13.6",
|
|
93
93
|
"dotenv": "~17.3.1",
|
|
94
94
|
"ethers": "^6.16.0",
|
|
95
95
|
"http-status-codes": "~2.3.0",
|
|
96
|
-
"mongodb": "~7.1.
|
|
96
|
+
"mongodb": "~7.1.1",
|
|
97
97
|
"nodemon": "~3.1.14",
|
|
98
98
|
"tslib": "~2.8.1",
|
|
99
99
|
"typescript": "~5.9.3",
|
|
@@ -3,13 +3,14 @@ import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
|
3
3
|
import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
makeBridgeConfigRoute, makeBridgeFromRemoteStatusRoute, makeBridgeToRemoteEstimateRoute, makeBridgeToRemoteRoute, makeBridgeToRemoteStatusRoute,
|
|
6
|
+
makeBridgeConfigRoute, makeBridgeFromRemoteStatusRoute, makeBridgeToRemoteEstimateRoute, makeBridgeToRemoteMaxEstimateRoute, makeBridgeToRemoteRoute, makeBridgeToRemoteStatusRoute,
|
|
7
7
|
} from './routes/index.ts'
|
|
8
8
|
|
|
9
9
|
export const getRouteDefinitions = (config: BridgeConfig, gateway: XyoGatewayRunner): RouteDefinition[] => {
|
|
10
10
|
return [
|
|
11
11
|
makeBridgeConfigRoute(config),
|
|
12
12
|
makeBridgeToRemoteEstimateRoute(config, gateway),
|
|
13
|
+
makeBridgeToRemoteMaxEstimateRoute(config, gateway),
|
|
13
14
|
makeBridgeToRemoteRoute(config),
|
|
14
15
|
makeBridgeToRemoteStatusRoute(config),
|
|
15
16
|
makeBridgeFromRemoteStatusRoute(config),
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RouteDefinition } from '@xylabs/express'
|
|
2
2
|
import { requestHandlerValidator } from '@xylabs/express'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
assertEx, hexToBigInt, toAddress,
|
|
5
|
+
} from '@xylabs/sdk-js'
|
|
4
6
|
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
5
7
|
import { PayloadZodStrictOfSchema } from '@xyo-network/sdk-js'
|
|
6
8
|
import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
@@ -9,7 +11,7 @@ import {
|
|
|
9
11
|
} from '@xyo-network/xl1-sdk'
|
|
10
12
|
import { z } from 'zod'
|
|
11
13
|
|
|
12
|
-
import { getXl1ChainId } from '../../../../../config/index.ts'
|
|
14
|
+
import { getBridgeSettings, getXl1ChainId } from '../../../../../config/index.ts'
|
|
13
15
|
import { generateBridgeEstimate } from '../../../../../util/index.ts'
|
|
14
16
|
import { getRemoteChainIdZod } from '../pathParams/index.ts'
|
|
15
17
|
|
|
@@ -41,6 +43,13 @@ export const makeBridgeToRemoteEstimateRoute = (config: BridgeConfig, gateway: X
|
|
|
41
43
|
const {
|
|
42
44
|
srcAddress, srcAmount, destAddress,
|
|
43
45
|
} = req.body
|
|
46
|
+
|
|
47
|
+
const { maxBridgeAmount } = await getBridgeSettings(config)
|
|
48
|
+
if (hexToBigInt(srcAmount) > hexToBigInt(maxBridgeAmount)) {
|
|
49
|
+
res.status(400).send()
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config)
|
|
45
54
|
const sender = toAddress(srcAddress)
|
|
46
55
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { RouteDefinition } from '@xylabs/express'
|
|
2
|
+
import { requestHandlerValidator } from '@xylabs/express'
|
|
3
|
+
import {
|
|
4
|
+
assertEx, hexToBigInt, toAddress, toHex,
|
|
5
|
+
} from '@xylabs/sdk-js'
|
|
6
|
+
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
7
|
+
import { PayloadZodStrictOfSchema } from '@xyo-network/sdk-js'
|
|
8
|
+
import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
9
|
+
import {
|
|
10
|
+
BridgeIntentFieldsZod, BridgeIntentSchema, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod,
|
|
11
|
+
} from '@xyo-network/xl1-sdk'
|
|
12
|
+
import { z } from 'zod'
|
|
13
|
+
|
|
14
|
+
import { getBridgeSettings } from '../../../../../config/index.ts'
|
|
15
|
+
import { calculateMaxBridgeAmount, generateBridgeEstimate } from '../../../../../util/index.ts'
|
|
16
|
+
import { getRemoteChainIdZod } from '../pathParams/index.ts'
|
|
17
|
+
|
|
18
|
+
export const BridgeToRemoteMaxEstimateBodyZod = BridgeIntentFieldsZod.pick({
|
|
19
|
+
destAddress: true,
|
|
20
|
+
srcAddress: true,
|
|
21
|
+
srcAmount: true,
|
|
22
|
+
})
|
|
23
|
+
export type BridgeToRemoteMaxEstimateBody = z.infer<typeof BridgeToRemoteMaxEstimateBodyZod>
|
|
24
|
+
|
|
25
|
+
export const BridgeToRemoteMaxEstimateResponseZod = z.tuple([
|
|
26
|
+
TransactionBoundWitnessZod,
|
|
27
|
+
PayloadZodStrictOfSchema(BridgeIntentSchema).extend(BridgeIntentFieldsZod.shape),
|
|
28
|
+
TransferZod,
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
export type BridgeToRemoteMaxEstimateResponse = z.infer<typeof BridgeToRemoteMaxEstimateResponseZod>
|
|
32
|
+
|
|
33
|
+
export const makeBridgeToRemoteMaxEstimateRoute = (config: BridgeConfig, gateway: XyoGatewayRunner): RouteDefinition => {
|
|
34
|
+
const params = z.object({ chainId: getRemoteChainIdZod(config) })
|
|
35
|
+
const validateRequest = requestHandlerValidator({
|
|
36
|
+
params, body: BridgeToRemoteMaxEstimateBodyZod, response: BridgeToRemoteMaxEstimateResponseZod,
|
|
37
|
+
})
|
|
38
|
+
return {
|
|
39
|
+
method: 'post',
|
|
40
|
+
path: '/bridge/chains/:chainId/bridgeToRemote/maxEstimate',
|
|
41
|
+
handlers: validateRequest(async (req, res) => {
|
|
42
|
+
const {
|
|
43
|
+
feeFixed, feeRateBasisPoints, maxBridgeAmount: configMax, xl1ChainId,
|
|
44
|
+
} = await getBridgeSettings(config)
|
|
45
|
+
const {
|
|
46
|
+
srcAddress, srcAmount: balance, destAddress,
|
|
47
|
+
} = req.body
|
|
48
|
+
|
|
49
|
+
const balanceMax = calculateMaxBridgeAmount(balance, { feeFixed, feeRateBasisPoints })
|
|
50
|
+
const maxBridgeAmount = toHex(hexToBigInt(balanceMax) < hexToBigInt(configMax) ? balanceMax : configMax)
|
|
51
|
+
|
|
52
|
+
const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, maxBridgeAmount, destAddress, config)
|
|
53
|
+
const sender = toAddress(srcAddress)
|
|
54
|
+
|
|
55
|
+
const viewer = assertEx(gateway.connection.viewer, () => new Error('Viewer not available on gateway connection'))
|
|
56
|
+
const currentBlockNumber = await viewer.currentBlockNumber()
|
|
57
|
+
const nbf = toXL1BlockNumber(currentBlockNumber, true)
|
|
58
|
+
const exp = toXL1BlockNumber(currentBlockNumber + 1000, true)
|
|
59
|
+
const [txBw] = await buildUnsignedTransaction(xl1ChainId, [transfer], [bridgeIntent], nbf, exp, sender)
|
|
60
|
+
|
|
61
|
+
res.json([txBw, bridgeIntent, transfer])
|
|
62
|
+
}),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Hex } from '@xylabs/sdk-js'
|
|
2
|
+
import { hexToBigInt, toHex } from '@xylabs/sdk-js'
|
|
3
|
+
|
|
4
|
+
import type { FeeStructure } from './calculateBridgeFees.ts'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Given a user's total available balance, calculates the maximum amount they can bridge
|
|
8
|
+
* after accounting for the fixed and variable bridge fees.
|
|
9
|
+
*
|
|
10
|
+
* Solving for M where: M + feeFixed + (M * basisPoints / 10_000) = balance
|
|
11
|
+
* => M = (balance - feeFixed) * 10_000 / (10_000 + basisPoints)
|
|
12
|
+
*/
|
|
13
|
+
export const calculateMaxBridgeAmount = (balance: Hex, feeStructure: FeeStructure): Hex => {
|
|
14
|
+
const { feeFixed, feeRateBasisPoints } = feeStructure
|
|
15
|
+
const balanceBigInt = hexToBigInt(balance)
|
|
16
|
+
const feeFixedBigInt = hexToBigInt(feeFixed)
|
|
17
|
+
|
|
18
|
+
if (balanceBigInt <= feeFixedBigInt) return toHex(0n)
|
|
19
|
+
|
|
20
|
+
const maxAmount = ((balanceBigInt - feeFixedBigInt) * 10_000n) / (10_000n + BigInt(feeRateBasisPoints))
|
|
21
|
+
return toHex(maxAmount)
|
|
22
|
+
}
|
package/src/util/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './BridgeFees.ts'
|
|
2
2
|
export * from './bridgeFeesAsBigInt.ts'
|
|
3
3
|
export * from './calculateBridgeFees.ts'
|
|
4
|
+
export * from './calculateMaxBridgeAmount.ts'
|
|
4
5
|
export * from './createBridgeTransfer.ts'
|
|
5
6
|
export * from './generateBridgeEstimate.ts'
|
|
6
7
|
export * from './getConfigFromEnv.ts'
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { isUndefined } from '@xylabs/sdk-js'
|
|
1
|
+
import { hexToBigInt, isUndefined } from '@xylabs/sdk-js'
|
|
2
2
|
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
3
3
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
4
4
|
import type { BridgeIntent, Transfer } from '@xyo-network/xl1-sdk'
|
|
5
5
|
|
|
6
|
+
import { getMaxBridgeAmount } from '../config/index.ts'
|
|
6
7
|
import { generateBridgeEstimate } from '../util/index.ts'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -21,6 +22,10 @@ export const validateBridgeEstimateExact = async (
|
|
|
21
22
|
const {
|
|
22
23
|
srcAddress, srcAmount, destAddress,
|
|
23
24
|
} = intent
|
|
25
|
+
|
|
26
|
+
// Reject if the requested amount exceeds the configured maximum
|
|
27
|
+
if (hexToBigInt(srcAmount) > hexToBigInt(getMaxBridgeAmount(config))) return false
|
|
28
|
+
|
|
24
29
|
const [calculatedIntent, calculatedTransfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config)
|
|
25
30
|
if (isUndefined(calculatedIntent) || isUndefined(calculatedTransfer)) return false
|
|
26
31
|
const { nonce: expectedIntentNonce, ...expectedIntentStatic } = calculatedIntent
|