otomato-sdk 1.5.5 → 1.5.6
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/src/constants/Blocks.js +6 -0
- package/dist/src/constants/tokens.js +1 -1
- package/dist/src/models/Action.js +2 -0
- package/dist/src/models/SessionKeyPermission.js +59 -19
- package/dist/types/src/constants/Blocks.d.ts +2 -0
- package/dist/types/src/models/SessionKeyPermission.d.ts +8 -1
- package/package.json +1 -1
|
@@ -537,6 +537,12 @@ export const ACTIONS = {
|
|
|
537
537
|
"permissions": {
|
|
538
538
|
"approvedTargets": [
|
|
539
539
|
"$contractAddress"
|
|
540
|
+
],
|
|
541
|
+
"label": [
|
|
542
|
+
"Transfer $tokenSymbol($chainId, $contractAddress)"
|
|
543
|
+
],
|
|
544
|
+
"labelNotAuthorized": [
|
|
545
|
+
"Transfer $otherTokenSymbol($chainId, $contractAddress)"
|
|
540
546
|
]
|
|
541
547
|
},
|
|
542
548
|
"blockId": 100004,
|
|
@@ -22,7 +22,7 @@ export const TOKENS = {
|
|
|
22
22
|
image: "https://static.debank.com/image/chain/logo_url/eth/42ba589cd077e7bdd97db6480b0ff61d.png"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
contractAddress: "
|
|
25
|
+
contractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7",
|
|
26
26
|
name: "USDT",
|
|
27
27
|
symbol: "USDT",
|
|
28
28
|
decimals: 18,
|
|
@@ -21,6 +21,8 @@ export class Action extends Node {
|
|
|
21
21
|
return null;
|
|
22
22
|
const permissions = SessionKeyPermission.fromJSON(parentBlock.permissions);
|
|
23
23
|
permissions.fill('contractAddress', this.getParameter('contractAddress'));
|
|
24
|
+
permissions.fill('chainId', this.getParameter('chainId'));
|
|
25
|
+
permissions.fillMethod();
|
|
24
26
|
return permissions;
|
|
25
27
|
}
|
|
26
28
|
static fromJSON(json) {
|
|
@@ -1,31 +1,57 @@
|
|
|
1
|
+
import { getToken } from "../constants/tokens.js";
|
|
1
2
|
export class SessionKeyPermission {
|
|
2
|
-
constructor(approvedTargets = []) {
|
|
3
|
-
if (!Array.isArray(approvedTargets)) {
|
|
4
|
-
console.error('approvedTargets should be an array. Received:', approvedTargets);
|
|
5
|
-
approvedTargets = [];
|
|
6
|
-
}
|
|
3
|
+
constructor({ approvedTargets = [], label = [], labelNotAuthorized = [], } = {}) {
|
|
7
4
|
this.approvedTargets = approvedTargets;
|
|
5
|
+
this.label = label;
|
|
6
|
+
this.labelNotAuthorized = labelNotAuthorized;
|
|
8
7
|
}
|
|
9
8
|
fill(key, value) {
|
|
10
|
-
|
|
11
|
-
console.error('approvedTargets is not an array. Cannot call map on:', this.approvedTargets);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
this.approvedTargets = this.approvedTargets.map(target => {
|
|
9
|
+
const replacePlaceholder = (target) => {
|
|
15
10
|
const placeholder = `$${key}`;
|
|
16
|
-
if (
|
|
17
|
-
|
|
11
|
+
if (target.includes(placeholder)) {
|
|
12
|
+
return target.replace(placeholder, value);
|
|
18
13
|
}
|
|
19
14
|
return target;
|
|
20
|
-
}
|
|
15
|
+
};
|
|
16
|
+
this.approvedTargets = this.approvedTargets.map(replacePlaceholder);
|
|
17
|
+
this.label = this.label.map(replacePlaceholder);
|
|
18
|
+
this.labelNotAuthorized = this.labelNotAuthorized.map(replacePlaceholder);
|
|
19
|
+
}
|
|
20
|
+
fillMethod() {
|
|
21
|
+
const executeMethod = (target) => {
|
|
22
|
+
const methodPattern = /\$(\w+)\(([^)]+)\)/g;
|
|
23
|
+
return target.replace(methodPattern, (match, methodName, params) => {
|
|
24
|
+
const paramList = params.split(',').map((param) => param.trim());
|
|
25
|
+
switch (methodName) {
|
|
26
|
+
case 'tokenSymbol': {
|
|
27
|
+
const [chainId, address] = paramList;
|
|
28
|
+
const token = getToken(parseInt(chainId, 10), address);
|
|
29
|
+
return token ? token.symbol : match;
|
|
30
|
+
}
|
|
31
|
+
case 'otherTokenSymbol': {
|
|
32
|
+
const [chainId, address] = paramList;
|
|
33
|
+
const symbol = getDifferentToken(parseInt(chainId, 10), address);
|
|
34
|
+
return symbol;
|
|
35
|
+
}
|
|
36
|
+
// Add other methods here as needed
|
|
37
|
+
default:
|
|
38
|
+
return match;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
this.approvedTargets = this.approvedTargets.map(executeMethod);
|
|
43
|
+
this.label = this.label.map(executeMethod);
|
|
44
|
+
this.labelNotAuthorized = this.labelNotAuthorized.map(executeMethod);
|
|
21
45
|
}
|
|
22
46
|
toJSON() {
|
|
23
|
-
const containsPlaceholder = this.approvedTargets.some(target =>
|
|
47
|
+
const containsPlaceholder = this.approvedTargets.some(target => target.includes('$'));
|
|
24
48
|
if (containsPlaceholder) {
|
|
25
49
|
throw new Error('Approved targets contain unresolved placeholders.');
|
|
26
50
|
}
|
|
27
51
|
return {
|
|
28
52
|
approvedTargets: this.approvedTargets,
|
|
53
|
+
label: this.label,
|
|
54
|
+
labelNotAuthorized: this.labelNotAuthorized,
|
|
29
55
|
};
|
|
30
56
|
}
|
|
31
57
|
static fromJSON(json) {
|
|
@@ -33,15 +59,29 @@ export class SessionKeyPermission {
|
|
|
33
59
|
console.error('Invalid JSON object for SessionKeyPermission:', json);
|
|
34
60
|
throw new Error('Invalid JSON object for SessionKeyPermission');
|
|
35
61
|
}
|
|
36
|
-
return new SessionKeyPermission(json
|
|
62
|
+
return new SessionKeyPermission(json);
|
|
37
63
|
}
|
|
38
64
|
merge(other) {
|
|
39
|
-
|
|
40
|
-
console.error('Invalid SessionKeyPermission object to merge:', other);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
65
|
+
// Merge approvedTargets
|
|
43
66
|
const uniqueTargets = new Set(this.approvedTargets);
|
|
44
67
|
other.approvedTargets.forEach(target => uniqueTargets.add(target));
|
|
45
68
|
this.approvedTargets = Array.from(uniqueTargets);
|
|
69
|
+
// Merge labels
|
|
70
|
+
const uniqueLabels = new Set(this.label);
|
|
71
|
+
other.label.forEach(lbl => uniqueLabels.add(lbl));
|
|
72
|
+
this.label = Array.from(uniqueLabels);
|
|
73
|
+
// Merge labelNotAuthorized
|
|
74
|
+
const uniqueLabelsNotAuthorized = new Set(this.labelNotAuthorized);
|
|
75
|
+
other.labelNotAuthorized.forEach(lbl => uniqueLabelsNotAuthorized.add(lbl));
|
|
76
|
+
this.labelNotAuthorized = Array.from(uniqueLabelsNotAuthorized);
|
|
77
|
+
// Remove labels from labelNotAuthorized if they are present in label
|
|
78
|
+
this.labelNotAuthorized = this.labelNotAuthorized.filter(lbl => !this.label.includes(lbl));
|
|
46
79
|
}
|
|
47
80
|
}
|
|
81
|
+
const getDifferentToken = (chain, contractAddress) => {
|
|
82
|
+
var _a;
|
|
83
|
+
const tokenSymbol = (_a = getToken(chain, contractAddress)) === null || _a === void 0 ? void 0 : _a.symbol;
|
|
84
|
+
if (!tokenSymbol || tokenSymbol !== 'WETH')
|
|
85
|
+
return 'WETH';
|
|
86
|
+
return 'USDT';
|
|
87
|
+
};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export declare class SessionKeyPermission {
|
|
2
2
|
approvedTargets: string[];
|
|
3
|
-
|
|
3
|
+
label: string[];
|
|
4
|
+
labelNotAuthorized: string[];
|
|
5
|
+
constructor({ approvedTargets, label, labelNotAuthorized, }?: {
|
|
6
|
+
approvedTargets?: string[];
|
|
7
|
+
label?: string[];
|
|
8
|
+
labelNotAuthorized?: string[];
|
|
9
|
+
});
|
|
4
10
|
fill(key: string, value: any): void;
|
|
11
|
+
fillMethod(): void;
|
|
5
12
|
toJSON(): {
|
|
6
13
|
[key: string]: any;
|
|
7
14
|
};
|