@lit-protocol/vincent-ability-erc20-approval 0.0.7-mma
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/CONTRIBUTING.md +89 -0
- package/README.md +76 -0
- package/dist/CHANGELOG.md +14 -0
- package/dist/CONTRIBUTING.md +89 -0
- package/dist/README.md +76 -0
- package/dist/package.json +29 -0
- package/dist/src/generated/lit-action.js +9 -0
- package/dist/src/generated/vincent-ability-metadata.json +3 -0
- package/dist/src/generated/vincent-bundled-ability.d.ts +65 -0
- package/dist/src/generated/vincent-bundled-ability.d.ts.map +1 -0
- package/dist/src/generated/vincent-bundled-ability.js +15 -0
- package/dist/src/generated/vincent-bundled-ability.js.map +1 -0
- package/dist/src/generated/vincent-bundled-ability.ts +13 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/helpers/check-native-token-balance.d.ts +6 -0
- package/dist/src/lib/helpers/check-native-token-balance.d.ts.map +1 -0
- package/dist/src/lib/helpers/check-native-token-balance.js +9 -0
- package/dist/src/lib/helpers/check-native-token-balance.js.map +1 -0
- package/dist/src/lib/helpers/get-current-allowance.d.ts +8 -0
- package/dist/src/lib/helpers/get-current-allowance.d.ts.map +1 -0
- package/dist/src/lib/helpers/get-current-allowance.js +11 -0
- package/dist/src/lib/helpers/get-current-allowance.js.map +1 -0
- package/dist/src/lib/helpers/getErc20Contract.d.ts +4 -0
- package/dist/src/lib/helpers/getErc20Contract.d.ts.map +1 -0
- package/dist/src/lib/helpers/getErc20Contract.js +20 -0
- package/dist/src/lib/helpers/getErc20Contract.js.map +1 -0
- package/dist/src/lib/helpers/index.d.ts +4 -0
- package/dist/src/lib/helpers/index.d.ts.map +1 -0
- package/dist/src/lib/helpers/index.js +10 -0
- package/dist/src/lib/helpers/index.js.map +1 -0
- package/dist/src/lib/lit-action-helpers/index.d.ts +3 -0
- package/dist/src/lib/lit-action-helpers/index.d.ts.map +1 -0
- package/dist/src/lib/lit-action-helpers/index.js +8 -0
- package/dist/src/lib/lit-action-helpers/index.js.map +1 -0
- package/dist/src/lib/lit-action-helpers/send-erc20-approval-tx.d.ts +10 -0
- package/dist/src/lib/lit-action-helpers/send-erc20-approval-tx.d.ts.map +1 -0
- package/dist/src/lib/lit-action-helpers/send-erc20-approval-tx.js +94 -0
- package/dist/src/lib/lit-action-helpers/send-erc20-approval-tx.js.map +1 -0
- package/dist/src/lib/lit-action-helpers/sign-tx.d.ts +3 -0
- package/dist/src/lib/lit-action-helpers/sign-tx.d.ts.map +1 -0
- package/dist/src/lib/lit-action-helpers/sign-tx.js +28 -0
- package/dist/src/lib/lit-action-helpers/sign-tx.js.map +1 -0
- package/dist/src/lib/lit-action.d.ts +2 -0
- package/dist/src/lib/lit-action.d.ts.map +1 -0
- package/dist/src/lib/lit-action.js +16 -0
- package/dist/src/lib/lit-action.js.map +1 -0
- package/dist/src/lib/schemas.d.ts +67 -0
- package/dist/src/lib/schemas.d.ts.map +1 -0
- package/dist/src/lib/schemas.js +59 -0
- package/dist/src/lib/schemas.js.map +1 -0
- package/dist/src/lib/vincent-ability.d.ts +62 -0
- package/dist/src/lib/vincent-ability.d.ts.map +1 -0
- package/dist/src/lib/vincent-ability.js +99 -0
- package/dist/src/lib/vincent-ability.js.map +1 -0
- package/package.json +28 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare const vincentAbility: import("@lit-protocol/vincent-ability-sdk").VincentAbility<import("zod").ZodObject<{
|
|
2
|
+
rpcUrl: import("zod").ZodString;
|
|
3
|
+
chainId: import("zod").ZodNumber;
|
|
4
|
+
spenderAddress: import("zod").ZodString;
|
|
5
|
+
tokenAddress: import("zod").ZodString;
|
|
6
|
+
tokenDecimals: import("zod").ZodNumber;
|
|
7
|
+
tokenAmount: import("zod").ZodNumber;
|
|
8
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
9
|
+
tokenAddress: string;
|
|
10
|
+
rpcUrl: string;
|
|
11
|
+
chainId: number;
|
|
12
|
+
spenderAddress: string;
|
|
13
|
+
tokenAmount: number;
|
|
14
|
+
tokenDecimals: number;
|
|
15
|
+
}, {
|
|
16
|
+
tokenAddress: string;
|
|
17
|
+
rpcUrl: string;
|
|
18
|
+
chainId: number;
|
|
19
|
+
spenderAddress: string;
|
|
20
|
+
tokenAmount: number;
|
|
21
|
+
tokenDecimals: number;
|
|
22
|
+
}>, string, import("node_modules/@lit-protocol/vincent-ability-sdk/dist/src/lib/abilityCore/helpers").AbilityPolicyMap<readonly [], never>, {}, import("zod").ZodObject<{
|
|
23
|
+
approvalTxHash: import("zod").ZodOptional<import("zod").ZodString>;
|
|
24
|
+
approvedAmount: import("zod").ZodString;
|
|
25
|
+
tokenAddress: import("zod").ZodString;
|
|
26
|
+
tokenDecimals: import("zod").ZodNumber;
|
|
27
|
+
spenderAddress: import("zod").ZodString;
|
|
28
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
29
|
+
tokenAddress: string;
|
|
30
|
+
spenderAddress: string;
|
|
31
|
+
tokenDecimals: number;
|
|
32
|
+
approvedAmount: string;
|
|
33
|
+
approvalTxHash?: string | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
tokenAddress: string;
|
|
36
|
+
spenderAddress: string;
|
|
37
|
+
tokenDecimals: number;
|
|
38
|
+
approvedAmount: string;
|
|
39
|
+
approvalTxHash?: string | undefined;
|
|
40
|
+
}>, import("zod").ZodObject<{
|
|
41
|
+
error: import("zod").ZodString;
|
|
42
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
43
|
+
error: string;
|
|
44
|
+
}, {
|
|
45
|
+
error: string;
|
|
46
|
+
}>, import("zod").ZodObject<{
|
|
47
|
+
alreadyApproved: import("zod").ZodBoolean;
|
|
48
|
+
currentAllowance: import("zod").ZodString;
|
|
49
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
50
|
+
alreadyApproved: boolean;
|
|
51
|
+
currentAllowance: string;
|
|
52
|
+
}, {
|
|
53
|
+
alreadyApproved: boolean;
|
|
54
|
+
currentAllowance: string;
|
|
55
|
+
}>, import("zod").ZodObject<{
|
|
56
|
+
noNativeTokenBalance: import("zod").ZodBoolean;
|
|
57
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
58
|
+
noNativeTokenBalance: boolean;
|
|
59
|
+
}, {
|
|
60
|
+
noNativeTokenBalance: boolean;
|
|
61
|
+
}>>;
|
|
62
|
+
//# sourceMappingURL=vincent-ability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vincent-ability.d.ts","sourceRoot":"","sources":["../../../src/lib/vincent-ability.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHzB,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vincentAbility = void 0;
|
|
4
|
+
const vincent_ability_sdk_1 = require("@lit-protocol/vincent-ability-sdk");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
const lit_action_helpers_1 = require("./lit-action-helpers");
|
|
8
|
+
const schemas_1 = require("./schemas");
|
|
9
|
+
exports.vincentAbility = (0, vincent_ability_sdk_1.createVincentAbility)({
|
|
10
|
+
packageName: '@lit-protocol/vincent-ability-erc20-approval',
|
|
11
|
+
abilityDescription: 'Allow, up to a limit, of an ERC20 token spending to another address.',
|
|
12
|
+
abilityParamsSchema: schemas_1.abilityParamsSchema,
|
|
13
|
+
supportedPolicies: (0, vincent_ability_sdk_1.supportedPoliciesForAbility)([]),
|
|
14
|
+
precheckSuccessSchema: schemas_1.precheckSuccessSchema,
|
|
15
|
+
precheckFailSchema: schemas_1.precheckFailSchema,
|
|
16
|
+
executeSuccessSchema: schemas_1.executeSuccessSchema,
|
|
17
|
+
executeFailSchema: schemas_1.executeFailSchema,
|
|
18
|
+
precheck: async ({ abilityParams }, { succeed, fail, delegation: { delegatorPkpInfo } }) => {
|
|
19
|
+
const { ethAddress } = delegatorPkpInfo;
|
|
20
|
+
const { rpcUrl, spenderAddress, tokenAddress, tokenDecimals, tokenAmount } = abilityParams;
|
|
21
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(rpcUrl);
|
|
22
|
+
const hasNativeTokenBalance = await (0, helpers_1.checkNativeTokenBalance)({
|
|
23
|
+
provider,
|
|
24
|
+
pkpEthAddress: ethAddress,
|
|
25
|
+
});
|
|
26
|
+
if (!hasNativeTokenBalance) {
|
|
27
|
+
return fail({ noNativeTokenBalance: true });
|
|
28
|
+
}
|
|
29
|
+
const currentAllowance = await (0, helpers_1.getCurrentAllowance)({
|
|
30
|
+
provider,
|
|
31
|
+
tokenAddress,
|
|
32
|
+
owner: ethAddress,
|
|
33
|
+
spender: spenderAddress,
|
|
34
|
+
});
|
|
35
|
+
const requiredAmount = ethers_1.ethers.utils.parseUnits(tokenAmount.toString(), tokenDecimals);
|
|
36
|
+
return succeed({
|
|
37
|
+
alreadyApproved: currentAllowance == requiredAmount.toBigInt(),
|
|
38
|
+
currentAllowance: currentAllowance.toString(),
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
execute: async ({ abilityParams }, { succeed, delegation: { delegatorPkpInfo } }) => {
|
|
42
|
+
console.log('Executing ERC20 Approval Ability');
|
|
43
|
+
const { ethAddress, publicKey } = delegatorPkpInfo;
|
|
44
|
+
const { rpcUrl, chainId, spenderAddress, tokenAddress, tokenDecimals, tokenAmount } = abilityParams;
|
|
45
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(rpcUrl);
|
|
46
|
+
await (0, helpers_1.checkNativeTokenBalance)({
|
|
47
|
+
provider,
|
|
48
|
+
pkpEthAddress: ethAddress,
|
|
49
|
+
});
|
|
50
|
+
const currentAllowance = await (0, helpers_1.getCurrentAllowance)({
|
|
51
|
+
provider,
|
|
52
|
+
tokenAddress,
|
|
53
|
+
owner: ethAddress,
|
|
54
|
+
spender: spenderAddress,
|
|
55
|
+
});
|
|
56
|
+
const requiredAmount = ethers_1.ethers.utils
|
|
57
|
+
.parseUnits(tokenAmount.toString(), tokenDecimals)
|
|
58
|
+
.toBigInt();
|
|
59
|
+
console.log(`currentAllowance: ${currentAllowance} >= requiredAmount: ${requiredAmount} (execute)`);
|
|
60
|
+
if (currentAllowance === requiredAmount) {
|
|
61
|
+
console.log('Ability execution successful', {
|
|
62
|
+
approvedAmount: currentAllowance.toString(),
|
|
63
|
+
spenderAddress,
|
|
64
|
+
tokenAddress,
|
|
65
|
+
tokenDecimals: parseInt(tokenDecimals.toString()),
|
|
66
|
+
});
|
|
67
|
+
return succeed({
|
|
68
|
+
approvedAmount: currentAllowance.toString(),
|
|
69
|
+
tokenAddress,
|
|
70
|
+
tokenDecimals: parseInt(tokenDecimals.toString()),
|
|
71
|
+
spenderAddress,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const approvalTxHash = await (0, lit_action_helpers_1.sendErc20ApprovalTx)({
|
|
75
|
+
rpcUrl,
|
|
76
|
+
chainId,
|
|
77
|
+
pkpEthAddress: ethAddress,
|
|
78
|
+
pkpPublicKey: publicKey,
|
|
79
|
+
spenderAddress,
|
|
80
|
+
tokenAmount: requiredAmount,
|
|
81
|
+
tokenAddress,
|
|
82
|
+
});
|
|
83
|
+
console.log('Ability execution successful', {
|
|
84
|
+
approvalTxHash,
|
|
85
|
+
approvedAmount: requiredAmount.toString(),
|
|
86
|
+
spenderAddress,
|
|
87
|
+
tokenAddress,
|
|
88
|
+
tokenDecimals: parseInt(tokenDecimals.toString()),
|
|
89
|
+
});
|
|
90
|
+
return succeed({
|
|
91
|
+
approvalTxHash,
|
|
92
|
+
approvedAmount: requiredAmount.toString(),
|
|
93
|
+
tokenAddress,
|
|
94
|
+
tokenDecimals: parseInt(tokenDecimals.toString()),
|
|
95
|
+
spenderAddress,
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=vincent-ability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vincent-ability.js","sourceRoot":"","sources":["../../../src/lib/vincent-ability.ts"],"names":[],"mappings":";;;AAAA,2EAG2C;AAC3C,mCAAgC;AAEhC,uCAAyE;AACzE,6DAA2D;AAC3D,uCAMmB;AAEN,QAAA,cAAc,GAAG,IAAA,0CAAoB,EAAC;IACjD,WAAW,EAAE,8CAAuD;IACpE,kBAAkB,EAChB,sEAA+E;IACjF,mBAAmB,EAAnB,6BAAmB;IACnB,iBAAiB,EAAE,IAAA,iDAA2B,EAAC,EAAE,CAAC;IAElD,qBAAqB,EAArB,+BAAqB;IACrB,kBAAkB,EAAlB,4BAAkB;IAElB,oBAAoB,EAApB,8BAAoB;IACpB,iBAAiB,EAAjB,2BAAiB;IAEjB,QAAQ,EAAE,KAAK,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,EAAE;QACzF,MAAM,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAAC;QACxC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,aAAa,CAAC;QAE3F,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAE9D,MAAM,qBAAqB,GAAG,MAAM,IAAA,iCAAuB,EAAC;YAC1D,QAAQ;YACR,aAAa,EAAE,UAAU;SAC1B,CAAC,CAAC;QAEH,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,C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Config": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"ethers": "^5.8.0",
|
|
9
|
+
"tslib": "2.8.1",
|
|
10
|
+
"zod": "^3.25.64",
|
|
11
|
+
"@lit-protocol/vincent-ability-sdk": "0.0.7-mma"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@lit-protocol/vincent-app-sdk": "^0.0.7-mma"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"esbuild": "^0.19.12",
|
|
18
|
+
"esbuild-plugin-polyfill-node": "^0.3.0",
|
|
19
|
+
"ipfs-only-hash": "^4.0.0"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/src/index.js",
|
|
22
|
+
"module": "./dist/src/index.js",
|
|
23
|
+
"types": "./dist/src/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist/**",
|
|
26
|
+
"*.md"
|
|
27
|
+
]
|
|
28
|
+
}
|