@seal-protocol/backendjs 0.0.129 → 0.0.131
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/lib/codegen/api/seal-client.d.ts +221 -107
- package/lib/codegen/api/seal-client.js +217 -117
- package/lib/codegen/model/index.d.ts +6 -3
- package/lib/codegen/model/index.js +6 -3
- package/lib/codegen/model/seal-chain.d.ts +1 -1
- package/lib/codegen/model/{seal-domain-info.d.ts → seal-get-order-stats-for-owner-response.d.ts} +6 -18
- package/lib/codegen/model/seal-get-rfq-activities-response.d.ts +31 -0
- package/lib/codegen/model/seal-rfq-activities-order-by-property.d.ts +22 -0
- package/lib/codegen/model/seal-rfq-activities-order-by-property.js +28 -0
- package/lib/codegen/model/seal-rfq-activities-order-by.d.ts +31 -0
- package/lib/codegen/model/{seal-approval-type.d.ts → seal-rfq-activities-order-by.js} +4 -11
- package/lib/codegen/model/seal-rfq-activity.d.ts +75 -0
- package/lib/codegen/model/seal-rfq-activity.js +15 -0
- package/lib/codegen/model/types-rfq-activity-type.d.ts +25 -0
- package/lib/codegen/model/types-rfq-activity-type.js +31 -0
- package/lib/utils/calculate-liquidity.d.ts +21 -1
- package/lib/utils/calculate-liquidity.js +54 -11
- package/lib/utils/calculate-required-permit.d.ts +36 -0
- package/lib/utils/calculate-required-permit.js +111 -0
- package/lib/utils/index.d.ts +3 -1
- package/lib/utils/index.js +20 -1
- package/package.json +1 -1
- package/lib/codegen/model/seal-approval-type.js +0 -28
- package/lib/codegen/model/seal-calculate-required-permit-response.d.ts +0 -74
- /package/lib/codegen/model/{seal-calculate-required-permit-response.js → seal-get-order-stats-for-owner-response.js} +0 -0
- /package/lib/codegen/model/{seal-domain-info.js → seal-get-rfq-activities-response.js} +0 -0
package/lib/codegen/model/{seal-domain-info.d.ts → seal-get-order-stats-for-owner-response.d.ts}
RENAMED
|
@@ -12,31 +12,19 @@
|
|
|
12
12
|
/**
|
|
13
13
|
*
|
|
14
14
|
* @export
|
|
15
|
-
* @interface
|
|
15
|
+
* @interface SealGetOrderStatsForOwnerResponse
|
|
16
16
|
*/
|
|
17
|
-
export interface
|
|
17
|
+
export interface SealGetOrderStatsForOwnerResponse {
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
20
20
|
* @type {string}
|
|
21
|
-
* @memberof
|
|
21
|
+
* @memberof SealGetOrderStatsForOwnerResponse
|
|
22
22
|
*/
|
|
23
|
-
'
|
|
23
|
+
'count'?: string;
|
|
24
24
|
/**
|
|
25
25
|
*
|
|
26
26
|
* @type {string}
|
|
27
|
-
* @memberof
|
|
27
|
+
* @memberof SealGetOrderStatsForOwnerResponse
|
|
28
28
|
*/
|
|
29
|
-
'
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
* @type {string}
|
|
33
|
-
* @memberof SealDomainInfo
|
|
34
|
-
*/
|
|
35
|
-
'verifyingContract'?: string;
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
* @type {string}
|
|
39
|
-
* @memberof SealDomainInfo
|
|
40
|
-
*/
|
|
41
|
-
'chainId'?: string;
|
|
29
|
+
'remaining'?: string;
|
|
42
30
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* seal/seal.proto
|
|
3
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: version not set
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
import type { SealRfqActivity } from './seal-rfq-activity';
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @export
|
|
16
|
+
* @interface SealGetRfqActivitiesResponse
|
|
17
|
+
*/
|
|
18
|
+
export interface SealGetRfqActivitiesResponse {
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @type {Array<SealRfqActivity>}
|
|
22
|
+
* @memberof SealGetRfqActivitiesResponse
|
|
23
|
+
*/
|
|
24
|
+
'activities': Array<SealRfqActivity>;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @type {string}
|
|
28
|
+
* @memberof SealGetRfqActivitiesResponse
|
|
29
|
+
*/
|
|
30
|
+
'paginationNextKey'?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* seal/seal.proto
|
|
3
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: version not set
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @enum {string}
|
|
16
|
+
*/
|
|
17
|
+
export declare enum SealRfqActivitiesOrderByProperty {
|
|
18
|
+
RfqActivitiesOrderByPropertyUnspecified = "RfqActivitiesOrderByProperty_UNSPECIFIED",
|
|
19
|
+
RfqActivitiesOrderByPropertyActivityId = "RfqActivitiesOrderByProperty_ACTIVITY_ID",
|
|
20
|
+
RfqActivitiesOrderByPropertyChainId = "RfqActivitiesOrderByProperty_CHAIN_ID",
|
|
21
|
+
RfqActivitiesOrderByPropertyActivityTime = "RfqActivitiesOrderByProperty_ACTIVITY_TIME"
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/**
|
|
5
|
+
* seal/seal.proto
|
|
6
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
7
|
+
*
|
|
8
|
+
* The version of the OpenAPI document: version not set
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
12
|
+
* https://openapi-generator.tech
|
|
13
|
+
* Do not edit the class manually.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.SealRfqActivitiesOrderByProperty = void 0;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @enum {string}
|
|
21
|
+
*/
|
|
22
|
+
var SealRfqActivitiesOrderByProperty;
|
|
23
|
+
(function (SealRfqActivitiesOrderByProperty) {
|
|
24
|
+
SealRfqActivitiesOrderByProperty["RfqActivitiesOrderByPropertyUnspecified"] = "RfqActivitiesOrderByProperty_UNSPECIFIED";
|
|
25
|
+
SealRfqActivitiesOrderByProperty["RfqActivitiesOrderByPropertyActivityId"] = "RfqActivitiesOrderByProperty_ACTIVITY_ID";
|
|
26
|
+
SealRfqActivitiesOrderByProperty["RfqActivitiesOrderByPropertyChainId"] = "RfqActivitiesOrderByProperty_CHAIN_ID";
|
|
27
|
+
SealRfqActivitiesOrderByProperty["RfqActivitiesOrderByPropertyActivityTime"] = "RfqActivitiesOrderByProperty_ACTIVITY_TIME";
|
|
28
|
+
})(SealRfqActivitiesOrderByProperty || (exports.SealRfqActivitiesOrderByProperty = SealRfqActivitiesOrderByProperty = {}));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* seal/seal.proto
|
|
3
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: version not set
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
import type { SealRfqActivitiesOrderByProperty } from './seal-rfq-activities-order-by-property';
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @export
|
|
16
|
+
* @interface SealRfqActivitiesOrderBy
|
|
17
|
+
*/
|
|
18
|
+
export interface SealRfqActivitiesOrderBy {
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @type {SealRfqActivitiesOrderByProperty}
|
|
22
|
+
* @memberof SealRfqActivitiesOrderBy
|
|
23
|
+
*/
|
|
24
|
+
'property'?: SealRfqActivitiesOrderByProperty;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @type {boolean}
|
|
28
|
+
* @memberof SealRfqActivitiesOrderBy
|
|
29
|
+
*/
|
|
30
|
+
'descending'?: boolean;
|
|
31
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
1
4
|
/**
|
|
2
5
|
* seal/seal.proto
|
|
3
6
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
@@ -9,14 +12,4 @@
|
|
|
9
12
|
* https://openapi-generator.tech
|
|
10
13
|
* Do not edit the class manually.
|
|
11
14
|
*/
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* @export
|
|
15
|
-
* @enum {string}
|
|
16
|
-
*/
|
|
17
|
-
export declare enum SealApprovalType {
|
|
18
|
-
ApprovalTypeUnspecified = "ApprovalType_UNSPECIFIED",
|
|
19
|
-
ApprovalTypeEip2612 = "ApprovalType_EIP2612",
|
|
20
|
-
ApprovalTypePermit2 = "ApprovalType_PERMIT2",
|
|
21
|
-
ApprovalTypeErc20 = "ApprovalType_ERC20"
|
|
22
|
-
}
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* seal/seal.proto
|
|
3
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: version not set
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
import type { SealRfqRequest } from './seal-rfq-request';
|
|
13
|
+
import type { TypesRfqActivityType } from './types-rfq-activity-type';
|
|
14
|
+
import type { TypesTimestamp } from './types-timestamp';
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @export
|
|
18
|
+
* @interface SealRfqActivity
|
|
19
|
+
*/
|
|
20
|
+
export interface SealRfqActivity {
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @type {string}
|
|
24
|
+
* @memberof SealRfqActivity
|
|
25
|
+
*/
|
|
26
|
+
'id'?: string;
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @type {string}
|
|
30
|
+
* @memberof SealRfqActivity
|
|
31
|
+
*/
|
|
32
|
+
'chainId'?: string;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @type {string}
|
|
36
|
+
* @memberof SealRfqActivity
|
|
37
|
+
*/
|
|
38
|
+
'requestId'?: string;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @type {TypesRfqActivityType}
|
|
42
|
+
* @memberof SealRfqActivity
|
|
43
|
+
*/
|
|
44
|
+
'activityType'?: TypesRfqActivityType;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @type {string}
|
|
48
|
+
* @memberof SealRfqActivity
|
|
49
|
+
*/
|
|
50
|
+
'data'?: string;
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @type {string}
|
|
54
|
+
* @memberof SealRfqActivity
|
|
55
|
+
*/
|
|
56
|
+
'txHash'?: string;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @type {TypesTimestamp}
|
|
60
|
+
* @memberof SealRfqActivity
|
|
61
|
+
*/
|
|
62
|
+
'time'?: TypesTimestamp;
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @type {string}
|
|
66
|
+
* @memberof SealRfqActivity
|
|
67
|
+
*/
|
|
68
|
+
'actor'?: string;
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @type {SealRfqRequest}
|
|
72
|
+
* @memberof SealRfqActivity
|
|
73
|
+
*/
|
|
74
|
+
'request': SealRfqRequest;
|
|
75
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/**
|
|
5
|
+
* seal/seal.proto
|
|
6
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
7
|
+
*
|
|
8
|
+
* The version of the OpenAPI document: version not set
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
12
|
+
* https://openapi-generator.tech
|
|
13
|
+
* Do not edit the class manually.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* seal/seal.proto
|
|
3
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: version not set
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @enum {string}
|
|
16
|
+
*/
|
|
17
|
+
export declare enum TypesRfqActivityType {
|
|
18
|
+
RfqActivityTypeUnspecified = "RFQ_ACTIVITY_TYPE_UNSPECIFIED",
|
|
19
|
+
RfqActivityTypeRequestSubmitted = "RFQ_ACTIVITY_TYPE_REQUEST_SUBMITTED",
|
|
20
|
+
RfqActivityTypeCommitmentSettled = "RFQ_ACTIVITY_TYPE_COMMITMENT_SETTLED",
|
|
21
|
+
RfqActivityTypeQuoteAccepted = "RFQ_ACTIVITY_TYPE_QUOTE_ACCEPTED",
|
|
22
|
+
RfqActivityTypeCommitmentDefaulted = "RFQ_ACTIVITY_TYPE_COMMITMENT_DEFAULTED",
|
|
23
|
+
RfqActivityTypeQuoteSubmitted = "RFQ_ACTIVITY_TYPE_QUOTE_SUBMITTED",
|
|
24
|
+
RfqActivityDefaultedCommitmentClosed = "RFQ_ACTIVITY_DEFAULTED_COMMITMENT_CLOSED"
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/**
|
|
5
|
+
* seal/seal.proto
|
|
6
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
7
|
+
*
|
|
8
|
+
* The version of the OpenAPI document: version not set
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
12
|
+
* https://openapi-generator.tech
|
|
13
|
+
* Do not edit the class manually.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TypesRfqActivityType = void 0;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @enum {string}
|
|
21
|
+
*/
|
|
22
|
+
var TypesRfqActivityType;
|
|
23
|
+
(function (TypesRfqActivityType) {
|
|
24
|
+
TypesRfqActivityType["RfqActivityTypeUnspecified"] = "RFQ_ACTIVITY_TYPE_UNSPECIFIED";
|
|
25
|
+
TypesRfqActivityType["RfqActivityTypeRequestSubmitted"] = "RFQ_ACTIVITY_TYPE_REQUEST_SUBMITTED";
|
|
26
|
+
TypesRfqActivityType["RfqActivityTypeCommitmentSettled"] = "RFQ_ACTIVITY_TYPE_COMMITMENT_SETTLED";
|
|
27
|
+
TypesRfqActivityType["RfqActivityTypeQuoteAccepted"] = "RFQ_ACTIVITY_TYPE_QUOTE_ACCEPTED";
|
|
28
|
+
TypesRfqActivityType["RfqActivityTypeCommitmentDefaulted"] = "RFQ_ACTIVITY_TYPE_COMMITMENT_DEFAULTED";
|
|
29
|
+
TypesRfqActivityType["RfqActivityTypeQuoteSubmitted"] = "RFQ_ACTIVITY_TYPE_QUOTE_SUBMITTED";
|
|
30
|
+
TypesRfqActivityType["RfqActivityDefaultedCommitmentClosed"] = "RFQ_ACTIVITY_DEFAULTED_COMMITMENT_CLOSED";
|
|
31
|
+
})(TypesRfqActivityType || (exports.TypesRfqActivityType = TypesRfqActivityType = {}));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Erc20 } from "../abi-types";
|
|
1
2
|
import { type SealTokenPermitApproval, SealTransferPermission } from "../codegen";
|
|
2
3
|
import { ContractRunner } from "ethers";
|
|
3
4
|
export type TransferPermission = {
|
|
@@ -22,4 +23,23 @@ export type CalculateLiquidityParams = {
|
|
|
22
23
|
minPermissionDurationMs: number;
|
|
23
24
|
permission?: SealTokenPermitApproval;
|
|
24
25
|
};
|
|
25
|
-
export declare function
|
|
26
|
+
export declare function fetchOnChainAllowance(params: {
|
|
27
|
+
provider: ContractRunner;
|
|
28
|
+
erc20Contract: Erc20;
|
|
29
|
+
owner: string;
|
|
30
|
+
spender: string;
|
|
31
|
+
token: string;
|
|
32
|
+
minPermissionDurationMs?: number;
|
|
33
|
+
deadlineUnixSeconds?: number;
|
|
34
|
+
permit2ContractAddress?: string;
|
|
35
|
+
requiredAmount?: bigint;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
onChainAllowance: bigint;
|
|
38
|
+
onChainAllowanceToPermit2Contract?: bigint;
|
|
39
|
+
onChainPermit2?: bigint;
|
|
40
|
+
maxAllowed?: bigint;
|
|
41
|
+
isRequiredAmountCovered: boolean;
|
|
42
|
+
permit2Nonce?: bigint;
|
|
43
|
+
}>;
|
|
44
|
+
declare function calculateLiquidity(params: CalculateLiquidityParams): Promise<LiquidityBreakdown>;
|
|
45
|
+
export default calculateLiquidity;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiquidityBreakdown = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.fetchOnChainAllowance = fetchOnChainAllowance;
|
|
5
5
|
const abi_types_1 = require("../abi-types");
|
|
6
6
|
const codegen_1 = require("../codegen");
|
|
7
7
|
class LiquidityBreakdown {
|
|
@@ -70,26 +70,48 @@ function effectiveOffchainAmount(p) {
|
|
|
70
70
|
return p.Permit2;
|
|
71
71
|
return 0n;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const erc20Contract = abi_types_1.Erc20__factory.connect(token, provider);
|
|
78
|
-
const permit2Contract = abi_types_1.Permit2__factory.connect(permit2, provider);
|
|
79
|
-
// 1) On-chain balance
|
|
80
|
-
const balance = await erc20Contract.balanceOf(owner);
|
|
73
|
+
// if the token does not support permit2 you can pass in undefined for permit2 contract
|
|
74
|
+
// if the requiredAmount was passed, not all on-chain permits would be fetched, and will fetch only as much as needed
|
|
75
|
+
async function fetchOnChainAllowance(params) {
|
|
76
|
+
const { provider, erc20Contract, owner, spender, token, minPermissionDurationMs, deadlineUnixSeconds, permit2ContractAddress, requiredAmount, } = params;
|
|
81
77
|
// 2) On-chain ERC20 allowance to spender
|
|
82
78
|
const onChainAllowance = await erc20Contract.allowance(owner, spender);
|
|
79
|
+
if (requiredAmount != null && onChainAllowance >= requiredAmount) {
|
|
80
|
+
return {
|
|
81
|
+
onChainAllowance: onChainAllowance,
|
|
82
|
+
isRequiredAmountCovered: true,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (permit2ContractAddress == null) {
|
|
86
|
+
return {
|
|
87
|
+
isRequiredAmountCovered: false,
|
|
88
|
+
maxAllowed: onChainAllowance,
|
|
89
|
+
onChainAllowance,
|
|
90
|
+
onChainAllowanceToPermit2Contract: 0n,
|
|
91
|
+
onChainPermit2: 0n
|
|
92
|
+
};
|
|
93
|
+
}
|
|
83
94
|
// 3) ERC20 allowance to Permit2 contract (if zero, Permit2 approvals are not usable)
|
|
84
|
-
const onChainAllowanceToPermit2Contract = await erc20Contract.allowance(owner,
|
|
95
|
+
const onChainAllowanceToPermit2Contract = await erc20Contract.allowance(owner, permit2ContractAddress);
|
|
96
|
+
if (requiredAmount != null && onChainAllowanceToPermit2Contract <= requiredAmount) {
|
|
97
|
+
return {
|
|
98
|
+
onChainAllowance,
|
|
99
|
+
isRequiredAmountCovered: false,
|
|
100
|
+
onChainAllowanceToPermit2Contract,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const permit2Contract = abi_types_1.Permit2__factory.connect(permit2ContractAddress, provider);
|
|
85
104
|
// 4) On-chain Permit2 allowance amount (subject to expiry), only if token->Permit2 allowance > 0
|
|
86
105
|
let onChainPermit2 = 0n;
|
|
106
|
+
let permit2Nonce;
|
|
87
107
|
if (onChainAllowanceToPermit2Contract > 0n) {
|
|
88
108
|
const result = await permit2Contract.allowance(owner, token, spender);
|
|
89
109
|
// tuple: [amount, expiration, nonce]
|
|
90
110
|
const amount = result[0];
|
|
91
111
|
const expiration = result[1];
|
|
92
|
-
|
|
112
|
+
permit2Nonce = result[2];
|
|
113
|
+
if (expiration === 0n || (minPermissionDurationMs != null && isCloseToExpiry(expiration, minPermissionDurationMs)) ||
|
|
114
|
+
(deadlineUnixSeconds != null && expiration <= BigInt(deadlineUnixSeconds))) {
|
|
93
115
|
onChainPermit2 = 0n;
|
|
94
116
|
}
|
|
95
117
|
else {
|
|
@@ -97,6 +119,26 @@ async function calculateLiquidity(params) {
|
|
|
97
119
|
}
|
|
98
120
|
}
|
|
99
121
|
let maxAllowed = maxBigInt(onChainAllowance, onChainPermit2);
|
|
122
|
+
return {
|
|
123
|
+
onChainPermit2,
|
|
124
|
+
onChainAllowanceToPermit2Contract,
|
|
125
|
+
onChainAllowance,
|
|
126
|
+
isRequiredAmountCovered: requiredAmount != null ? maxAllowed >= requiredAmount : false,
|
|
127
|
+
maxAllowed,
|
|
128
|
+
permit2Nonce,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async function calculateLiquidity(params) {
|
|
132
|
+
const { provider, owner, token, spender, permit2, minPermissionDurationMs } = params;
|
|
133
|
+
let backendPermission = params.permission ? { ...params.permission } : null;
|
|
134
|
+
// Contracts
|
|
135
|
+
const erc20Contract = abi_types_1.Erc20__factory.connect(token, provider);
|
|
136
|
+
// 1) On-chain balance
|
|
137
|
+
const balance = await erc20Contract.balanceOf(owner);
|
|
138
|
+
let { onChainAllowance, onChainAllowanceToPermit2Contract, onChainPermit2, maxAllowed } = await fetchOnChainAllowance({
|
|
139
|
+
provider, erc20Contract, owner, spender, permit2ContractAddress: permit2, token,
|
|
140
|
+
minPermissionDurationMs,
|
|
141
|
+
});
|
|
100
142
|
let permission = {};
|
|
101
143
|
// 5) Validate optional off-chain permission against on-chain state and expiry windows
|
|
102
144
|
if (backendPermission) {
|
|
@@ -132,3 +174,4 @@ async function calculateLiquidity(params) {
|
|
|
132
174
|
const spendable = minBigInt(maxAllowed, balance);
|
|
133
175
|
return new LiquidityBreakdown(spendable, balance, onChainAllowance, onChainPermit2, permission);
|
|
134
176
|
}
|
|
177
|
+
exports.default = calculateLiquidity;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SealClient, SealPermit2Contract, SealSealContract, SealToken } from "../codegen";
|
|
2
|
+
import { ContractRunner } from "ethers";
|
|
3
|
+
export declare enum ApprovalType {
|
|
4
|
+
Eip2612 = 1,// user signed an EIP-2612 permit
|
|
5
|
+
Permit2 = 2,// user used Uniswap Permit2
|
|
6
|
+
Erc20 = 3
|
|
7
|
+
}
|
|
8
|
+
export interface DomainInfo {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
verifyingContract: string;
|
|
12
|
+
chainId: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CalculateRequiredPermitForOrderResponse {
|
|
15
|
+
ordersCount: bigint;
|
|
16
|
+
ordersRemaining: bigint;
|
|
17
|
+
permit?: {
|
|
18
|
+
approvalType: ApprovalType;
|
|
19
|
+
domainInfo?: DomainInfo;
|
|
20
|
+
allowance: bigint;
|
|
21
|
+
nonce?: bigint;
|
|
22
|
+
spender: string;
|
|
23
|
+
sigDeadline?: bigint;
|
|
24
|
+
expiration?: bigint;
|
|
25
|
+
};
|
|
26
|
+
permit2Contract?: SealPermit2Contract;
|
|
27
|
+
}
|
|
28
|
+
export declare function calculateRequiredPermitForOrder(params: {
|
|
29
|
+
provider: ContractRunner;
|
|
30
|
+
client: SealClient;
|
|
31
|
+
inputToken: SealToken;
|
|
32
|
+
owner: string;
|
|
33
|
+
amountIn: bigint;
|
|
34
|
+
sealContract?: SealSealContract;
|
|
35
|
+
expirationTimeSeconds: number;
|
|
36
|
+
}): Promise<CalculateRequiredPermitForOrderResponse>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApprovalType = void 0;
|
|
4
|
+
exports.calculateRequiredPermitForOrder = calculateRequiredPermitForOrder;
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const calculate_liquidity_1 = require("./calculate-liquidity");
|
|
7
|
+
const abi_types_1 = require("../abi-types");
|
|
8
|
+
const maxUint32 = BigInt(Math.pow(2, 32) - 1);
|
|
9
|
+
var ApprovalType;
|
|
10
|
+
(function (ApprovalType) {
|
|
11
|
+
ApprovalType[ApprovalType["Eip2612"] = 1] = "Eip2612";
|
|
12
|
+
ApprovalType[ApprovalType["Permit2"] = 2] = "Permit2";
|
|
13
|
+
ApprovalType[ApprovalType["Erc20"] = 3] = "Erc20";
|
|
14
|
+
})(ApprovalType || (exports.ApprovalType = ApprovalType = {}));
|
|
15
|
+
async function calculateRequiredPermitForOrder(params) {
|
|
16
|
+
let { provider, client, inputToken, owner, amountIn, sealContract, expirationTimeSeconds, } = params;
|
|
17
|
+
const chainId = inputToken.chainId;
|
|
18
|
+
if (sealContract == null) {
|
|
19
|
+
const contracts = (await client.getSealContracts({
|
|
20
|
+
chainId
|
|
21
|
+
})).data.contracts;
|
|
22
|
+
if (contracts.length < 1) {
|
|
23
|
+
throw new Error("no contract support for the given chain");
|
|
24
|
+
}
|
|
25
|
+
sealContract = contracts[0];
|
|
26
|
+
}
|
|
27
|
+
const stats = (await client.getOrderStatsForOwner({
|
|
28
|
+
chainId, owner, tokenIn: inputToken.address,
|
|
29
|
+
})).data;
|
|
30
|
+
const ordersCount = BigInt(stats.count);
|
|
31
|
+
const ordersRemaining = BigInt(stats.remaining);
|
|
32
|
+
const requiredAllowance = ordersRemaining + amountIn;
|
|
33
|
+
const approvals = (await client.getTokenPermitApprovals({
|
|
34
|
+
owner, spender: sealContract.address, chainId,
|
|
35
|
+
})).data.approvals;
|
|
36
|
+
if (approvals.length > 0 && Number(approvals[0].sigDeadline.seconds) >= expirationTimeSeconds && (approvals[0].allowanceExpiration == null || Number(approvals[0].allowanceExpiration.seconds) >= expirationTimeSeconds)) {
|
|
37
|
+
const allowance = BigInt(approvals[0].allowance);
|
|
38
|
+
if (allowance >= requiredAllowance) {
|
|
39
|
+
return {
|
|
40
|
+
ordersCount,
|
|
41
|
+
ordersRemaining,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let permit2 = (await client.getPermit2Contracts()).data.contracts.find(c => c.chainId == chainId);
|
|
46
|
+
const erc20Contract = abi_types_1.Erc20__factory.connect(inputToken.address, provider);
|
|
47
|
+
let { onChainAllowanceToPermit2Contract, permit2Nonce, isRequiredAmountCovered } = await (0, calculate_liquidity_1.fetchOnChainAllowance)({
|
|
48
|
+
provider, erc20Contract, owner, spender: sealContract.address,
|
|
49
|
+
permit2ContractAddress: permit2?.address, token: inputToken.address,
|
|
50
|
+
requiredAmount: requiredAllowance, deadlineUnixSeconds: expirationTimeSeconds,
|
|
51
|
+
});
|
|
52
|
+
if (isRequiredAmountCovered) {
|
|
53
|
+
return {
|
|
54
|
+
ordersCount,
|
|
55
|
+
ordersRemaining,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (inputToken.isErc2612 === true) {
|
|
59
|
+
const permitContract = abi_types_1.Erc20Permit__factory.connect(inputToken.address, provider);
|
|
60
|
+
const nonce = await permitContract.nonces(owner);
|
|
61
|
+
return {
|
|
62
|
+
ordersCount,
|
|
63
|
+
ordersRemaining,
|
|
64
|
+
permit: {
|
|
65
|
+
nonce,
|
|
66
|
+
allowance: ethers_1.MaxUint256,
|
|
67
|
+
approvalType: ApprovalType.Eip2612,
|
|
68
|
+
spender: sealContract.address,
|
|
69
|
+
domainInfo: {
|
|
70
|
+
name: inputToken.contractName,
|
|
71
|
+
version: inputToken.contractVersion,
|
|
72
|
+
verifyingContract: inputToken.address,
|
|
73
|
+
chainId,
|
|
74
|
+
},
|
|
75
|
+
sigDeadline: maxUint32,
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// TODO isn't it better to ask the user to submit a permit2 allowance for onChainAllowanceToPermit2Contract,
|
|
80
|
+
// so he will be able to use permit2 from now on?
|
|
81
|
+
if (onChainAllowanceToPermit2Contract != null && onChainAllowanceToPermit2Contract >= requiredAllowance) {
|
|
82
|
+
return {
|
|
83
|
+
ordersCount,
|
|
84
|
+
ordersRemaining,
|
|
85
|
+
permit: {
|
|
86
|
+
nonce: permit2Nonce,
|
|
87
|
+
allowance: ethers_1.MaxUint256,
|
|
88
|
+
approvalType: ApprovalType.Permit2,
|
|
89
|
+
spender: sealContract.address,
|
|
90
|
+
domainInfo: {
|
|
91
|
+
name: permit2.domainSeparatorName,
|
|
92
|
+
version: permit2.domainSeparatorVersion,
|
|
93
|
+
verifyingContract: permit2.address,
|
|
94
|
+
chainId,
|
|
95
|
+
},
|
|
96
|
+
sigDeadline: maxUint32,
|
|
97
|
+
expiration: maxUint32,
|
|
98
|
+
},
|
|
99
|
+
permit2Contract: permit2,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
ordersCount,
|
|
104
|
+
ordersRemaining,
|
|
105
|
+
permit: {
|
|
106
|
+
allowance: requiredAllowance,
|
|
107
|
+
approvalType: ApprovalType.Erc20,
|
|
108
|
+
spender: sealContract.address,
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { LiquidityBreakdown, TransferPermission
|
|
1
|
+
export { LiquidityBreakdown, TransferPermission } from "./calculate-liquidity";
|
|
2
|
+
export { default as calculateLiquidity } from "./calculate-liquidity";
|
|
2
3
|
export { truncateFixedNumberToBigInt } from "./numbers";
|
|
4
|
+
export * from "./calculate-required-permit";
|
package/lib/utils/index.js
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
2
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
20
|
exports.truncateFixedNumberToBigInt = exports.calculateLiquidity = exports.LiquidityBreakdown = void 0;
|
|
4
21
|
var calculate_liquidity_1 = require("./calculate-liquidity");
|
|
5
22
|
Object.defineProperty(exports, "LiquidityBreakdown", { enumerable: true, get: function () { return calculate_liquidity_1.LiquidityBreakdown; } });
|
|
6
|
-
|
|
23
|
+
var calculate_liquidity_2 = require("./calculate-liquidity");
|
|
24
|
+
Object.defineProperty(exports, "calculateLiquidity", { enumerable: true, get: function () { return __importDefault(calculate_liquidity_2).default; } });
|
|
7
25
|
var numbers_1 = require("./numbers");
|
|
8
26
|
Object.defineProperty(exports, "truncateFixedNumberToBigInt", { enumerable: true, get: function () { return numbers_1.truncateFixedNumberToBigInt; } });
|
|
27
|
+
__exportStar(require("./calculate-required-permit"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seal-protocol/backendjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.131",
|
|
4
4
|
"description": "Javascript SDK for Seal Backend",
|
|
5
5
|
"author": "amin <amin@refractedlabs.com>",
|
|
6
6
|
"homepage": "https://github.com/seal-protocol/backend/tree/main/ts-client#readme",
|