@virtuals-protocol/acp-node 0.3.0-beta.4 → 0.3.0-beta.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/index.d.mts +72 -142
- package/dist/index.d.ts +72 -142
- package/dist/index.js +452 -883
- package/dist/index.mjs +446 -877
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ var require_package = __commonJS({
|
|
|
28
28
|
"package.json"(exports, module) {
|
|
29
29
|
module.exports = {
|
|
30
30
|
name: "@virtuals-protocol/acp-node",
|
|
31
|
-
version: "0.3.0-beta.
|
|
31
|
+
version: "0.3.0-beta.6",
|
|
32
32
|
main: "./dist/index.js",
|
|
33
33
|
module: "./dist/index.mjs",
|
|
34
34
|
types: "./dist/index.d.ts",
|
|
@@ -43,9 +43,9 @@ var require_package = __commonJS({
|
|
|
43
43
|
typescript: "^5.8.3"
|
|
44
44
|
},
|
|
45
45
|
dependencies: {
|
|
46
|
-
"@aa-sdk/core": "^4.
|
|
47
|
-
"@account-kit/infra": "^4.
|
|
48
|
-
"@account-kit/smart-contracts": "^4.
|
|
46
|
+
"@aa-sdk/core": "^4.73.0",
|
|
47
|
+
"@account-kit/infra": "^4.73.0",
|
|
48
|
+
"@account-kit/smart-contracts": "^4.73.0",
|
|
49
49
|
ajv: "^8.17.1",
|
|
50
50
|
"socket.io-client": "^4.8.1",
|
|
51
51
|
tsup: "^8.5.0",
|
|
@@ -1832,6 +1832,7 @@ var ACP_ABI = [
|
|
|
1832
1832
|
var acpAbi_default = ACP_ABI;
|
|
1833
1833
|
|
|
1834
1834
|
// src/acpClient.ts
|
|
1835
|
+
import { zeroAddress as zeroAddress2 } from "viem";
|
|
1835
1836
|
import { io } from "socket.io-client";
|
|
1836
1837
|
|
|
1837
1838
|
// src/contractClients/baseAcpContractClient.ts
|
|
@@ -3014,171 +3015,160 @@ var BaseAcpContractClient = class {
|
|
|
3014
3015
|
return this.agentWalletAddress;
|
|
3015
3016
|
}
|
|
3016
3017
|
createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
} catch (error) {
|
|
3038
|
-
throw new acpError_default("Failed to create job with account", error);
|
|
3039
|
-
}
|
|
3040
|
-
});
|
|
3018
|
+
try {
|
|
3019
|
+
const data = encodeFunctionData({
|
|
3020
|
+
abi: this.abi,
|
|
3021
|
+
functionName: "createJobWithAccount",
|
|
3022
|
+
args: [
|
|
3023
|
+
accountId,
|
|
3024
|
+
evaluatorAddress,
|
|
3025
|
+
budgetBaseUnit,
|
|
3026
|
+
paymentTokenAddress,
|
|
3027
|
+
Math.floor(expiredAt.getTime() / 1e3)
|
|
3028
|
+
]
|
|
3029
|
+
});
|
|
3030
|
+
const payload = {
|
|
3031
|
+
data,
|
|
3032
|
+
contractAddress: this.contractAddress
|
|
3033
|
+
};
|
|
3034
|
+
return payload;
|
|
3035
|
+
} catch (error) {
|
|
3036
|
+
throw new acpError_default("Failed to create job with account", error);
|
|
3037
|
+
}
|
|
3041
3038
|
}
|
|
3042
3039
|
createJob(providerAddress, evaluatorAddress, expiredAt, paymentTokenAddress, budgetBaseUnit, metadata) {
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
} catch (error) {
|
|
3065
|
-
throw new acpError_default("Failed to create job", error);
|
|
3066
|
-
}
|
|
3067
|
-
});
|
|
3040
|
+
try {
|
|
3041
|
+
const data = encodeFunctionData({
|
|
3042
|
+
abi: this.abi,
|
|
3043
|
+
functionName: "createJob",
|
|
3044
|
+
args: [
|
|
3045
|
+
providerAddress,
|
|
3046
|
+
evaluatorAddress,
|
|
3047
|
+
Math.floor(expiredAt.getTime() / 1e3),
|
|
3048
|
+
paymentTokenAddress,
|
|
3049
|
+
budgetBaseUnit,
|
|
3050
|
+
metadata
|
|
3051
|
+
]
|
|
3052
|
+
});
|
|
3053
|
+
const payload = {
|
|
3054
|
+
data,
|
|
3055
|
+
contractAddress: this.contractAddress
|
|
3056
|
+
};
|
|
3057
|
+
return payload;
|
|
3058
|
+
} catch (error) {
|
|
3059
|
+
throw new acpError_default("Failed to create job", error);
|
|
3060
|
+
}
|
|
3068
3061
|
}
|
|
3069
|
-
approveAllowance(
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
})
|
|
3062
|
+
approveAllowance(amountBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
|
|
3063
|
+
try {
|
|
3064
|
+
const data = encodeFunctionData({
|
|
3065
|
+
abi: erc20Abi2,
|
|
3066
|
+
functionName: "approve",
|
|
3067
|
+
args: [this.contractAddress, amountBaseUnit]
|
|
3068
|
+
});
|
|
3069
|
+
const payload = {
|
|
3070
|
+
data,
|
|
3071
|
+
contractAddress: paymentTokenAddress
|
|
3072
|
+
};
|
|
3073
|
+
return payload;
|
|
3074
|
+
} catch (error) {
|
|
3075
|
+
throw new acpError_default("Failed to approve allowance", error);
|
|
3076
|
+
}
|
|
3082
3077
|
}
|
|
3083
|
-
createPayableMemo(
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
})
|
|
3078
|
+
createPayableMemo(jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
|
|
3079
|
+
try {
|
|
3080
|
+
const data = encodeFunctionData({
|
|
3081
|
+
abi: this.abi,
|
|
3082
|
+
functionName: "createPayableMemo",
|
|
3083
|
+
args: [
|
|
3084
|
+
jobId,
|
|
3085
|
+
content,
|
|
3086
|
+
token,
|
|
3087
|
+
amountBaseUnit,
|
|
3088
|
+
recipient,
|
|
3089
|
+
feeAmountBaseUnit,
|
|
3090
|
+
feeType,
|
|
3091
|
+
type,
|
|
3092
|
+
Math.floor(expiredAt.getTime() / 1e3),
|
|
3093
|
+
secured,
|
|
3094
|
+
nextPhase
|
|
3095
|
+
]
|
|
3096
|
+
});
|
|
3097
|
+
const payload = {
|
|
3098
|
+
data,
|
|
3099
|
+
contractAddress: this.contractAddress
|
|
3100
|
+
};
|
|
3101
|
+
return payload;
|
|
3102
|
+
} catch (error) {
|
|
3103
|
+
throw new acpError_default("Failed to create payable memo", error);
|
|
3104
|
+
}
|
|
3108
3105
|
}
|
|
3109
3106
|
createMemo(jobId, content, type, isSecured, nextPhase) {
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
})
|
|
3107
|
+
try {
|
|
3108
|
+
const data = encodeFunctionData({
|
|
3109
|
+
abi: this.abi,
|
|
3110
|
+
functionName: "createMemo",
|
|
3111
|
+
args: [jobId, content, type, isSecured, nextPhase]
|
|
3112
|
+
});
|
|
3113
|
+
const payload = {
|
|
3114
|
+
data,
|
|
3115
|
+
contractAddress: this.contractAddress
|
|
3116
|
+
};
|
|
3117
|
+
return payload;
|
|
3118
|
+
} catch (error) {
|
|
3119
|
+
throw new acpError_default("Failed to create memo", error);
|
|
3120
|
+
}
|
|
3122
3121
|
}
|
|
3123
3122
|
signMemo(memoId, isApproved, reason) {
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
}
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3123
|
+
try {
|
|
3124
|
+
const data = encodeFunctionData({
|
|
3125
|
+
abi: this.abi,
|
|
3126
|
+
functionName: "signMemo",
|
|
3127
|
+
args: [memoId, isApproved, reason]
|
|
3128
|
+
});
|
|
3129
|
+
const payload = {
|
|
3130
|
+
data,
|
|
3131
|
+
contractAddress: this.contractAddress
|
|
3132
|
+
};
|
|
3133
|
+
return payload;
|
|
3134
|
+
} catch (error) {
|
|
3135
|
+
throw new acpError_default("Failed to sign memo", error);
|
|
3136
|
+
}
|
|
3137
3137
|
}
|
|
3138
|
-
setBudgetWithPaymentToken(
|
|
3139
|
-
return
|
|
3140
|
-
try {
|
|
3141
|
-
const data = encodeFunctionData({
|
|
3142
|
-
abi: this.abi,
|
|
3143
|
-
functionName: "setBudgetWithPaymentToken",
|
|
3144
|
-
args: [jobId, budgetBaseUnit, paymentTokenAddress]
|
|
3145
|
-
});
|
|
3146
|
-
return yield this.handleOperation(data, this.contractAddress);
|
|
3147
|
-
} catch (error) {
|
|
3148
|
-
throw new acpError_default("Failed to set budget", error);
|
|
3149
|
-
}
|
|
3150
|
-
});
|
|
3138
|
+
setBudgetWithPaymentToken(jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
|
|
3139
|
+
return void 0;
|
|
3151
3140
|
}
|
|
3152
3141
|
updateAccountMetadata(accountId, metadata) {
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
})
|
|
3142
|
+
try {
|
|
3143
|
+
const data = encodeFunctionData({
|
|
3144
|
+
abi: this.abi,
|
|
3145
|
+
functionName: "updateAccountMetadata",
|
|
3146
|
+
args: [accountId, metadata]
|
|
3147
|
+
});
|
|
3148
|
+
const payload = {
|
|
3149
|
+
data,
|
|
3150
|
+
contractAddress: this.contractAddress
|
|
3151
|
+
};
|
|
3152
|
+
return payload;
|
|
3153
|
+
} catch (error) {
|
|
3154
|
+
throw new acpError_default("Failed to update account metadata", error);
|
|
3155
|
+
}
|
|
3165
3156
|
}
|
|
3166
3157
|
wrapEth(amountBaseUnit) {
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
});
|
|
3158
|
+
try {
|
|
3159
|
+
const data = encodeFunctionData({
|
|
3160
|
+
abi: wethAbi_default,
|
|
3161
|
+
functionName: "deposit"
|
|
3162
|
+
});
|
|
3163
|
+
const payload = {
|
|
3164
|
+
data,
|
|
3165
|
+
contractAddress: wethFare.contractAddress,
|
|
3166
|
+
value: amountBaseUnit
|
|
3167
|
+
};
|
|
3168
|
+
return payload;
|
|
3169
|
+
} catch (error) {
|
|
3170
|
+
throw new acpError_default("Failed to wrap eth", error);
|
|
3171
|
+
}
|
|
3182
3172
|
}
|
|
3183
3173
|
};
|
|
3184
3174
|
var baseAcpContractClient_default = BaseAcpContractClient;
|
|
@@ -3292,9 +3282,7 @@ var AcpJob = class {
|
|
|
3292
3282
|
if (requestMemo) {
|
|
3293
3283
|
return requestMemo.signedReason;
|
|
3294
3284
|
}
|
|
3295
|
-
return (_a = this.memos.find(
|
|
3296
|
-
(m) => m.nextPhase === 5 /* REJECTED */
|
|
3297
|
-
)) == null ? void 0 : _a.content;
|
|
3285
|
+
return (_a = this.memos.find((m) => m.nextPhase === 5 /* REJECTED */)) == null ? void 0 : _a.content;
|
|
3298
3286
|
}
|
|
3299
3287
|
get providerAgent() {
|
|
3300
3288
|
return this.acpClient.getAgent(this.providerAddress);
|
|
@@ -3313,36 +3301,46 @@ var AcpJob = class {
|
|
|
3313
3301
|
}
|
|
3314
3302
|
createRequirement(content) {
|
|
3315
3303
|
return __async(this, null, function* () {
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3304
|
+
const operations = [];
|
|
3305
|
+
operations.push(
|
|
3306
|
+
this.acpContractClient.createMemo(
|
|
3307
|
+
this.id,
|
|
3308
|
+
content,
|
|
3309
|
+
0 /* MESSAGE */,
|
|
3310
|
+
true,
|
|
3311
|
+
2 /* TRANSACTION */
|
|
3312
|
+
)
|
|
3322
3313
|
);
|
|
3314
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3323
3315
|
});
|
|
3324
3316
|
}
|
|
3325
3317
|
createPayableRequirement(_0, _1, _2, _3) {
|
|
3326
3318
|
return __async(this, arguments, function* (content, type, amount, recipient, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
|
|
3319
|
+
const operations = [];
|
|
3327
3320
|
if (type === 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3321
|
+
operations.push(
|
|
3322
|
+
this.acpContractClient.approveAllowance(
|
|
3323
|
+
amount.amount,
|
|
3324
|
+
amount.fare.contractAddress
|
|
3325
|
+
)
|
|
3331
3326
|
);
|
|
3332
3327
|
}
|
|
3333
3328
|
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
|
|
3334
|
-
|
|
3335
|
-
this.
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3329
|
+
operations.push(
|
|
3330
|
+
this.acpContractClient.createPayableMemo(
|
|
3331
|
+
this.id,
|
|
3332
|
+
content,
|
|
3333
|
+
amount.amount,
|
|
3334
|
+
recipient,
|
|
3335
|
+
feeAmount.amount,
|
|
3336
|
+
0 /* NO_FEE */,
|
|
3337
|
+
2 /* TRANSACTION */,
|
|
3338
|
+
type,
|
|
3339
|
+
expiredAt,
|
|
3340
|
+
amount.fare.contractAddress
|
|
3341
|
+
)
|
|
3345
3342
|
);
|
|
3343
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3346
3344
|
});
|
|
3347
3345
|
}
|
|
3348
3346
|
payAndAcceptRequirement(reason) {
|
|
@@ -3351,8 +3349,9 @@ var AcpJob = class {
|
|
|
3351
3349
|
(m) => m.nextPhase === 2 /* TRANSACTION */
|
|
3352
3350
|
);
|
|
3353
3351
|
if (!memo) {
|
|
3354
|
-
throw new acpError_default("No
|
|
3352
|
+
throw new acpError_default("No notification memo found");
|
|
3355
3353
|
}
|
|
3354
|
+
const operations = [];
|
|
3356
3355
|
const baseFareAmount = new FareAmount(this.price, this.baseFare);
|
|
3357
3356
|
const transferAmount = memo.payableDetails ? yield FareAmountBase.fromContractAddress(
|
|
3358
3357
|
memo.payableDetails.amount,
|
|
@@ -3360,24 +3359,31 @@ var AcpJob = class {
|
|
|
3360
3359
|
this.config
|
|
3361
3360
|
) : new FareAmount(0, this.baseFare);
|
|
3362
3361
|
const totalAmount = baseFareAmount.fare.contractAddress === transferAmount.fare.contractAddress ? baseFareAmount.add(transferAmount) : baseFareAmount;
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3362
|
+
operations.push(
|
|
3363
|
+
this.acpContractClient.approveAllowance(
|
|
3364
|
+
totalAmount.amount,
|
|
3365
|
+
this.baseFare.contractAddress
|
|
3366
|
+
)
|
|
3366
3367
|
);
|
|
3367
3368
|
if (baseFareAmount.fare.contractAddress !== transferAmount.fare.contractAddress) {
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3369
|
+
operations.push(
|
|
3370
|
+
this.acpContractClient.approveAllowance(
|
|
3371
|
+
transferAmount.amount,
|
|
3372
|
+
transferAmount.fare.contractAddress
|
|
3373
|
+
)
|
|
3371
3374
|
);
|
|
3372
3375
|
}
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
this.
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3376
|
+
operations.push(this.acpContractClient.signMemo(memo.id, true, reason));
|
|
3377
|
+
operations.push(
|
|
3378
|
+
this.acpContractClient.createMemo(
|
|
3379
|
+
this.id,
|
|
3380
|
+
`Payment made. ${reason != null ? reason : ""}`.trim(),
|
|
3381
|
+
0 /* MESSAGE */,
|
|
3382
|
+
true,
|
|
3383
|
+
3 /* EVALUATION */
|
|
3384
|
+
)
|
|
3380
3385
|
);
|
|
3386
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3381
3387
|
});
|
|
3382
3388
|
}
|
|
3383
3389
|
respond(accept, reason) {
|
|
@@ -3392,33 +3398,63 @@ var AcpJob = class {
|
|
|
3392
3398
|
}
|
|
3393
3399
|
accept(reason) {
|
|
3394
3400
|
return __async(this, null, function* () {
|
|
3395
|
-
var _a;
|
|
3396
3401
|
const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
|
|
3397
|
-
|
|
3398
|
-
|
|
3402
|
+
const latestMemo = this.latestMemo;
|
|
3403
|
+
if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
|
|
3404
|
+
throw new acpError_default("No request memo found");
|
|
3399
3405
|
}
|
|
3400
|
-
|
|
3401
|
-
yield memo.sign(true, memoContent);
|
|
3406
|
+
return yield latestMemo.sign(true, memoContent);
|
|
3402
3407
|
});
|
|
3403
3408
|
}
|
|
3404
3409
|
reject(reason) {
|
|
3405
3410
|
return __async(this, null, function* () {
|
|
3406
|
-
var _a;
|
|
3407
3411
|
const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
|
|
3408
3412
|
if (this.phase === 0 /* REQUEST */) {
|
|
3409
|
-
|
|
3413
|
+
const latestMemo = this.latestMemo;
|
|
3414
|
+
if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
|
|
3410
3415
|
throw new acpError_default("No request memo found");
|
|
3411
3416
|
}
|
|
3412
|
-
|
|
3413
|
-
return yield this.acpContractClient.signMemo(memo.id, false, memoContent);
|
|
3417
|
+
return yield latestMemo.sign(false, memoContent);
|
|
3414
3418
|
}
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3419
|
+
const operations = [];
|
|
3420
|
+
operations.push(
|
|
3421
|
+
this.acpContractClient.createMemo(
|
|
3422
|
+
this.id,
|
|
3423
|
+
memoContent,
|
|
3424
|
+
0 /* MESSAGE */,
|
|
3425
|
+
true,
|
|
3426
|
+
5 /* REJECTED */
|
|
3427
|
+
)
|
|
3421
3428
|
);
|
|
3429
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3430
|
+
});
|
|
3431
|
+
}
|
|
3432
|
+
rejectPayable() {
|
|
3433
|
+
return __async(this, arguments, function* (reason = "", amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
|
|
3434
|
+
const memoContent = `Job ${this.id} rejected. ${reason}`;
|
|
3435
|
+
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
|
|
3436
|
+
const operations = [];
|
|
3437
|
+
operations.push(
|
|
3438
|
+
this.acpContractClient.approveAllowance(
|
|
3439
|
+
amount.amount,
|
|
3440
|
+
amount.fare.contractAddress
|
|
3441
|
+
)
|
|
3442
|
+
);
|
|
3443
|
+
operations.push(
|
|
3444
|
+
this.acpContractClient.createPayableMemo(
|
|
3445
|
+
this.id,
|
|
3446
|
+
memoContent,
|
|
3447
|
+
amount.amount,
|
|
3448
|
+
this.clientAddress,
|
|
3449
|
+
feeAmount.amount,
|
|
3450
|
+
0 /* NO_FEE */,
|
|
3451
|
+
5 /* REJECTED */,
|
|
3452
|
+
7 /* PAYABLE_TRANSFER */,
|
|
3453
|
+
expiredAt,
|
|
3454
|
+
amount.fare.contractAddress
|
|
3455
|
+
)
|
|
3456
|
+
);
|
|
3457
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3422
3458
|
});
|
|
3423
3459
|
}
|
|
3424
3460
|
deliver(deliverable) {
|
|
@@ -3427,13 +3463,17 @@ var AcpJob = class {
|
|
|
3427
3463
|
if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
|
|
3428
3464
|
throw new acpError_default("No transaction memo found");
|
|
3429
3465
|
}
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3466
|
+
const operations = [];
|
|
3467
|
+
operations.push(
|
|
3468
|
+
this.acpContractClient.createMemo(
|
|
3469
|
+
this.id,
|
|
3470
|
+
preparePayload(deliverable),
|
|
3471
|
+
0 /* MESSAGE */,
|
|
3472
|
+
true,
|
|
3473
|
+
4 /* COMPLETED */
|
|
3474
|
+
)
|
|
3436
3475
|
);
|
|
3476
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3437
3477
|
});
|
|
3438
3478
|
}
|
|
3439
3479
|
deliverPayable(_0, _1) {
|
|
@@ -3442,23 +3482,29 @@ var AcpJob = class {
|
|
|
3442
3482
|
if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
|
|
3443
3483
|
throw new acpError_default("No transaction memo found");
|
|
3444
3484
|
}
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3485
|
+
const operations = [];
|
|
3486
|
+
operations.push(
|
|
3487
|
+
this.acpContractClient.approveAllowance(
|
|
3488
|
+
amount.amount,
|
|
3489
|
+
amount.fare.contractAddress
|
|
3490
|
+
)
|
|
3448
3491
|
);
|
|
3449
3492
|
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
|
|
3450
|
-
|
|
3451
|
-
this.
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3493
|
+
operations.push(
|
|
3494
|
+
this.acpContractClient.createPayableMemo(
|
|
3495
|
+
this.id,
|
|
3496
|
+
preparePayload(deliverable),
|
|
3497
|
+
amount.amount,
|
|
3498
|
+
this.clientAddress,
|
|
3499
|
+
feeAmount.amount,
|
|
3500
|
+
0 /* NO_FEE */,
|
|
3501
|
+
4 /* COMPLETED */,
|
|
3502
|
+
7 /* PAYABLE_TRANSFER */,
|
|
3503
|
+
expiredAt,
|
|
3504
|
+
amount.fare.contractAddress
|
|
3505
|
+
)
|
|
3461
3506
|
);
|
|
3507
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3462
3508
|
});
|
|
3463
3509
|
}
|
|
3464
3510
|
evaluate(accept, reason) {
|
|
@@ -3471,419 +3517,46 @@ var AcpJob = class {
|
|
|
3471
3517
|
yield memo.sign(accept, reason);
|
|
3472
3518
|
});
|
|
3473
3519
|
}
|
|
3474
|
-
pay(reason) {
|
|
3475
|
-
return __async(this, null, function* () {
|
|
3476
|
-
const memo = this.memos.find(
|
|
3477
|
-
(m) => m.nextPhase === 2 /* TRANSACTION */
|
|
3478
|
-
);
|
|
3479
|
-
if (!memo) {
|
|
3480
|
-
throw new acpError_default("No transaction memo found");
|
|
3481
|
-
}
|
|
3482
|
-
return yield this.acpClient.payJob(
|
|
3483
|
-
this.id,
|
|
3484
|
-
this.baseFare.formatAmount(this.price),
|
|
3485
|
-
memo.id,
|
|
3486
|
-
reason
|
|
3487
|
-
);
|
|
3488
|
-
});
|
|
3489
|
-
}
|
|
3490
3520
|
createNotification(content) {
|
|
3491
3521
|
return __async(this, null, function* () {
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3522
|
+
const operations = [];
|
|
3523
|
+
operations.push(
|
|
3524
|
+
this.acpContractClient.createMemo(
|
|
3525
|
+
this.id,
|
|
3526
|
+
content,
|
|
3527
|
+
9 /* NOTIFICATION */,
|
|
3528
|
+
true,
|
|
3529
|
+
4 /* COMPLETED */
|
|
3530
|
+
)
|
|
3498
3531
|
);
|
|
3532
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3499
3533
|
});
|
|
3500
3534
|
}
|
|
3501
3535
|
createPayableNotification(_0, _1) {
|
|
3502
3536
|
return __async(this, arguments, function* (content, amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3537
|
+
const operations = [];
|
|
3538
|
+
operations.push(
|
|
3539
|
+
this.acpContractClient.approveAllowance(
|
|
3540
|
+
amount.amount,
|
|
3541
|
+
amount.fare.contractAddress
|
|
3542
|
+
)
|
|
3506
3543
|
);
|
|
3507
3544
|
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
|
|
3508
|
-
|
|
3509
|
-
this.
|
|
3510
|
-
content,
|
|
3511
|
-
amount.amount,
|
|
3512
|
-
this.clientAddress,
|
|
3513
|
-
feeAmount.amount,
|
|
3514
|
-
0 /* NO_FEE */,
|
|
3515
|
-
4 /* COMPLETED */,
|
|
3516
|
-
10 /* PAYABLE_NOTIFICATION */,
|
|
3517
|
-
expiredAt,
|
|
3518
|
-
amount.fare.contractAddress
|
|
3519
|
-
);
|
|
3520
|
-
});
|
|
3521
|
-
}
|
|
3522
|
-
// to be deprecated
|
|
3523
|
-
/**
|
|
3524
|
-
* @deprecated The method should not be used
|
|
3525
|
-
*/
|
|
3526
|
-
openPosition(_0, _1) {
|
|
3527
|
-
return __async(this, arguments, function* (payload, feeAmount, expiredAt = new Date(Date.now() + 1e3 * 60 * 3), walletAddress) {
|
|
3528
|
-
if (payload.length === 0) {
|
|
3529
|
-
throw new acpError_default("No positions to open");
|
|
3530
|
-
}
|
|
3531
|
-
const sumAmount = payload.reduce((acc, curr) => acc + curr.amount, 0);
|
|
3532
|
-
return yield this.acpClient.transferFunds(
|
|
3533
|
-
this.id,
|
|
3534
|
-
new FareAmount(sumAmount, this.baseFare),
|
|
3535
|
-
walletAddress || this.providerAddress,
|
|
3536
|
-
new FareAmount(feeAmount, this.baseFare),
|
|
3537
|
-
1 /* IMMEDIATE_FEE */,
|
|
3538
|
-
{
|
|
3539
|
-
type: "open_position" /* OPEN_POSITION */,
|
|
3540
|
-
data: payload
|
|
3541
|
-
},
|
|
3542
|
-
2 /* TRANSACTION */,
|
|
3543
|
-
expiredAt
|
|
3544
|
-
);
|
|
3545
|
-
});
|
|
3546
|
-
}
|
|
3547
|
-
/**
|
|
3548
|
-
* @deprecated The method should not be used
|
|
3549
|
-
*/
|
|
3550
|
-
swapToken(payload, decimals, feeAmount, walletAddress) {
|
|
3551
|
-
return __async(this, null, function* () {
|
|
3552
|
-
return yield this.acpClient.transferFunds(
|
|
3553
|
-
this.id,
|
|
3554
|
-
new FareAmount(
|
|
3555
|
-
payload.amount,
|
|
3556
|
-
new Fare(payload.fromContractAddress, decimals)
|
|
3557
|
-
),
|
|
3558
|
-
walletAddress || this.providerAddress,
|
|
3559
|
-
new FareAmount(feeAmount, this.baseFare),
|
|
3560
|
-
1 /* IMMEDIATE_FEE */,
|
|
3561
|
-
{
|
|
3562
|
-
type: "swap_token" /* SWAP_TOKEN */,
|
|
3563
|
-
data: payload
|
|
3564
|
-
},
|
|
3565
|
-
2 /* TRANSACTION */,
|
|
3566
|
-
new Date(Date.now() + 1e3 * 60 * 30)
|
|
3567
|
-
);
|
|
3568
|
-
});
|
|
3569
|
-
}
|
|
3570
|
-
/**
|
|
3571
|
-
* @deprecated The method should not be used
|
|
3572
|
-
*/
|
|
3573
|
-
responseSwapToken(memoId, accept, reason) {
|
|
3574
|
-
return __async(this, null, function* () {
|
|
3575
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3576
|
-
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
3577
|
-
throw new acpError_default("No swap token memo found");
|
|
3578
|
-
}
|
|
3579
|
-
const payload = tryParseJson(
|
|
3580
|
-
memo.content
|
|
3581
|
-
);
|
|
3582
|
-
if ((payload == null ? void 0 : payload.type) !== "swap_token" /* SWAP_TOKEN */) {
|
|
3583
|
-
throw new acpError_default("Invalid swap token memo");
|
|
3584
|
-
}
|
|
3585
|
-
return yield memo.sign(accept, reason);
|
|
3586
|
-
});
|
|
3587
|
-
}
|
|
3588
|
-
/**
|
|
3589
|
-
* @deprecated The method should not be used
|
|
3590
|
-
*/
|
|
3591
|
-
transferFunds(_0, _1, _2) {
|
|
3592
|
-
return __async(this, arguments, function* (payload, fareAmount, walletAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 30)) {
|
|
3593
|
-
return yield this.acpClient.transferFunds(
|
|
3594
|
-
this.id,
|
|
3595
|
-
fareAmount,
|
|
3596
|
-
walletAddress || this.clientAddress,
|
|
3597
|
-
new FareAmount(0, this.baseFare),
|
|
3598
|
-
0 /* NO_FEE */,
|
|
3599
|
-
payload,
|
|
3600
|
-
2 /* TRANSACTION */,
|
|
3601
|
-
expiredAt
|
|
3602
|
-
);
|
|
3603
|
-
});
|
|
3604
|
-
}
|
|
3605
|
-
/**
|
|
3606
|
-
* @deprecated The method should not be used
|
|
3607
|
-
*/
|
|
3608
|
-
responseOpenPosition(memoId, accept, reason) {
|
|
3609
|
-
return __async(this, null, function* () {
|
|
3610
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3611
|
-
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
3612
|
-
throw new acpError_default("No open position memo found");
|
|
3613
|
-
}
|
|
3614
|
-
const payload = tryParseJson(
|
|
3615
|
-
memo.content
|
|
3616
|
-
);
|
|
3617
|
-
if ((payload == null ? void 0 : payload.type) !== "open_position" /* OPEN_POSITION */) {
|
|
3618
|
-
throw new acpError_default("Invalid open position memo");
|
|
3619
|
-
}
|
|
3620
|
-
return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
|
|
3621
|
-
});
|
|
3622
|
-
}
|
|
3623
|
-
/**
|
|
3624
|
-
* @deprecated The method should not be used
|
|
3625
|
-
*/
|
|
3626
|
-
closePartialPosition(_0) {
|
|
3627
|
-
return __async(this, arguments, function* (payload, expireAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3628
|
-
return yield this.acpClient.requestFunds(
|
|
3629
|
-
this.id,
|
|
3630
|
-
new FareAmount(payload.amount, this.baseFare),
|
|
3631
|
-
this.clientAddress,
|
|
3632
|
-
new FareAmount(0, this.baseFare),
|
|
3633
|
-
0 /* NO_FEE */,
|
|
3634
|
-
{
|
|
3635
|
-
type: "close_partial_position" /* CLOSE_PARTIAL_POSITION */,
|
|
3636
|
-
data: payload
|
|
3637
|
-
},
|
|
3638
|
-
2 /* TRANSACTION */,
|
|
3639
|
-
expireAt
|
|
3640
|
-
);
|
|
3641
|
-
});
|
|
3642
|
-
}
|
|
3643
|
-
/**
|
|
3644
|
-
* @deprecated The method should not be used
|
|
3645
|
-
*/
|
|
3646
|
-
responseClosePartialPosition(memoId, accept, reason) {
|
|
3647
|
-
return __async(this, null, function* () {
|
|
3648
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3649
|
-
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 6 /* PAYABLE_REQUEST */) {
|
|
3650
|
-
throw new acpError_default("No close position memo found");
|
|
3651
|
-
}
|
|
3652
|
-
const payload = tryParseJson(
|
|
3653
|
-
memo.content
|
|
3654
|
-
);
|
|
3655
|
-
if ((payload == null ? void 0 : payload.type) !== "close_partial_position" /* CLOSE_PARTIAL_POSITION */) {
|
|
3656
|
-
throw new acpError_default("Invalid close position memo");
|
|
3657
|
-
}
|
|
3658
|
-
return yield this.acpClient.responseFundsRequest(
|
|
3659
|
-
memo.id,
|
|
3660
|
-
accept,
|
|
3661
|
-
this.baseFare.formatAmount(payload.data.amount),
|
|
3662
|
-
reason
|
|
3663
|
-
);
|
|
3664
|
-
});
|
|
3665
|
-
}
|
|
3666
|
-
/**
|
|
3667
|
-
* @deprecated The method should not be used
|
|
3668
|
-
*/
|
|
3669
|
-
requestClosePosition(payload) {
|
|
3670
|
-
return __async(this, null, function* () {
|
|
3671
|
-
return yield this.acpClient.sendMessage(
|
|
3672
|
-
this.id,
|
|
3673
|
-
{
|
|
3674
|
-
type: "close_position" /* CLOSE_POSITION */,
|
|
3675
|
-
data: payload
|
|
3676
|
-
},
|
|
3677
|
-
2 /* TRANSACTION */
|
|
3678
|
-
);
|
|
3679
|
-
});
|
|
3680
|
-
}
|
|
3681
|
-
/**
|
|
3682
|
-
* @deprecated The method should not be used
|
|
3683
|
-
*/
|
|
3684
|
-
responseRequestClosePosition(_0, _1, _2, _3) {
|
|
3685
|
-
return __async(this, arguments, function* (memoId, accept, payload, reason, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3686
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3687
|
-
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
|
|
3688
|
-
throw new acpError_default("No message memo found");
|
|
3689
|
-
}
|
|
3690
|
-
const messagePayload = tryParseJson(memo.content);
|
|
3691
|
-
if ((messagePayload == null ? void 0 : messagePayload.type) !== "close_position" /* CLOSE_POSITION */) {
|
|
3692
|
-
throw new acpError_default("Invalid close position memo");
|
|
3693
|
-
}
|
|
3694
|
-
yield memo.sign(accept, reason);
|
|
3695
|
-
if (accept) {
|
|
3696
|
-
return yield this.acpClient.transferFunds(
|
|
3545
|
+
operations.push(
|
|
3546
|
+
this.acpContractClient.createPayableMemo(
|
|
3697
3547
|
this.id,
|
|
3698
|
-
|
|
3548
|
+
content,
|
|
3549
|
+
amount.amount,
|
|
3699
3550
|
this.clientAddress,
|
|
3700
|
-
|
|
3551
|
+
feeAmount.amount,
|
|
3701
3552
|
0 /* NO_FEE */,
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
expiredAt
|
|
3708
|
-
);
|
|
3709
|
-
}
|
|
3710
|
-
});
|
|
3711
|
-
}
|
|
3712
|
-
/**
|
|
3713
|
-
* @deprecated The method should not be used
|
|
3714
|
-
*/
|
|
3715
|
-
confirmClosePosition(memoId, accept, reason) {
|
|
3716
|
-
return __async(this, null, function* () {
|
|
3717
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3718
|
-
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
3719
|
-
throw new acpError_default("No payable transfer memo found");
|
|
3720
|
-
}
|
|
3721
|
-
const payload = tryParseJson(
|
|
3722
|
-
memo.content
|
|
3723
|
-
);
|
|
3724
|
-
if ((payload == null ? void 0 : payload.type) !== "close_position" /* CLOSE_POSITION */) {
|
|
3725
|
-
throw new acpError_default("Invalid close position memo");
|
|
3726
|
-
}
|
|
3727
|
-
yield memo.sign(accept, reason);
|
|
3728
|
-
});
|
|
3729
|
-
}
|
|
3730
|
-
/**
|
|
3731
|
-
* @deprecated The method should not be used
|
|
3732
|
-
*/
|
|
3733
|
-
positionFulfilled(_0) {
|
|
3734
|
-
return __async(this, arguments, function* (payload, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3735
|
-
return yield this.acpClient.transferFunds(
|
|
3736
|
-
this.id,
|
|
3737
|
-
new FareAmount(payload.amount, this.baseFare),
|
|
3738
|
-
this.clientAddress,
|
|
3739
|
-
new FareAmount(0, this.baseFare),
|
|
3740
|
-
0 /* NO_FEE */,
|
|
3741
|
-
{
|
|
3742
|
-
type: "position_fulfilled" /* POSITION_FULFILLED */,
|
|
3743
|
-
data: payload
|
|
3744
|
-
},
|
|
3745
|
-
2 /* TRANSACTION */,
|
|
3746
|
-
expiredAt
|
|
3747
|
-
);
|
|
3748
|
-
});
|
|
3749
|
-
}
|
|
3750
|
-
/**
|
|
3751
|
-
* @deprecated The method should not be used
|
|
3752
|
-
*/
|
|
3753
|
-
unfulfilledPosition(_0) {
|
|
3754
|
-
return __async(this, arguments, function* (payload, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3755
|
-
return yield this.acpClient.transferFunds(
|
|
3756
|
-
this.id,
|
|
3757
|
-
new FareAmount(payload.amount, this.baseFare),
|
|
3758
|
-
this.clientAddress,
|
|
3759
|
-
new FareAmount(0, this.baseFare),
|
|
3760
|
-
0 /* NO_FEE */,
|
|
3761
|
-
{
|
|
3762
|
-
type: "unfulfilled_position" /* UNFULFILLED_POSITION */,
|
|
3763
|
-
data: payload
|
|
3764
|
-
},
|
|
3765
|
-
2 /* TRANSACTION */,
|
|
3766
|
-
expiredAt
|
|
3767
|
-
);
|
|
3768
|
-
});
|
|
3769
|
-
}
|
|
3770
|
-
/**
|
|
3771
|
-
* @deprecated The method should not be used
|
|
3772
|
-
*/
|
|
3773
|
-
responseUnfulfilledPosition(memoId, accept, reason) {
|
|
3774
|
-
return __async(this, null, function* () {
|
|
3775
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3776
|
-
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
3777
|
-
throw new acpError_default("No unfulfilled position memo found");
|
|
3778
|
-
}
|
|
3779
|
-
const payload = tryParseJson(
|
|
3780
|
-
memo.content
|
|
3781
|
-
);
|
|
3782
|
-
if ((payload == null ? void 0 : payload.type) !== "unfulfilled_position" /* UNFULFILLED_POSITION */) {
|
|
3783
|
-
throw new acpError_default("Invalid unfulfilled position memo");
|
|
3784
|
-
}
|
|
3785
|
-
return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
|
|
3786
|
-
});
|
|
3787
|
-
}
|
|
3788
|
-
/**
|
|
3789
|
-
* @deprecated The method should not be used
|
|
3790
|
-
*/
|
|
3791
|
-
responsePositionFulfilled(memoId, accept, reason) {
|
|
3792
|
-
return __async(this, null, function* () {
|
|
3793
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3794
|
-
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
3795
|
-
throw new acpError_default("No position fulfilled memo found");
|
|
3796
|
-
}
|
|
3797
|
-
const payload = tryParseJson(
|
|
3798
|
-
memo.content
|
|
3799
|
-
);
|
|
3800
|
-
if ((payload == null ? void 0 : payload.type) !== "position_fulfilled" /* POSITION_FULFILLED */) {
|
|
3801
|
-
throw new acpError_default("Invalid position fulfilled memo");
|
|
3802
|
-
}
|
|
3803
|
-
return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
|
|
3804
|
-
});
|
|
3805
|
-
}
|
|
3806
|
-
/**
|
|
3807
|
-
* @deprecated The method should not be used
|
|
3808
|
-
*/
|
|
3809
|
-
closeJob(message = "Close job and withdraw all") {
|
|
3810
|
-
return __async(this, null, function* () {
|
|
3811
|
-
return yield this.acpClient.sendMessage(
|
|
3812
|
-
this.id,
|
|
3813
|
-
{
|
|
3814
|
-
type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
|
|
3815
|
-
data: {
|
|
3816
|
-
message
|
|
3817
|
-
}
|
|
3818
|
-
},
|
|
3819
|
-
2 /* TRANSACTION */
|
|
3820
|
-
);
|
|
3821
|
-
});
|
|
3822
|
-
}
|
|
3823
|
-
/**
|
|
3824
|
-
* @deprecated The method should not be used
|
|
3825
|
-
*/
|
|
3826
|
-
responseCloseJob(_0, _1, _2, _3) {
|
|
3827
|
-
return __async(this, arguments, function* (memoId, accept, fulfilledPositions, reason, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3828
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3829
|
-
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
|
|
3830
|
-
throw new acpError_default("No message memo found");
|
|
3831
|
-
}
|
|
3832
|
-
const payload = tryParseJson(
|
|
3833
|
-
memo.content
|
|
3834
|
-
);
|
|
3835
|
-
if ((payload == null ? void 0 : payload.type) !== "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */) {
|
|
3836
|
-
throw new acpError_default("Invalid close job and withdraw memo");
|
|
3837
|
-
}
|
|
3838
|
-
yield memo.sign(accept, reason);
|
|
3839
|
-
if (!accept) {
|
|
3840
|
-
return;
|
|
3841
|
-
}
|
|
3842
|
-
const totalAmount = fulfilledPositions.reduce(
|
|
3843
|
-
(acc, curr) => acc + curr.amount,
|
|
3844
|
-
0
|
|
3845
|
-
);
|
|
3846
|
-
if (totalAmount === 0) {
|
|
3847
|
-
return yield this.acpClient.sendMessage(
|
|
3848
|
-
this.id,
|
|
3849
|
-
{
|
|
3850
|
-
type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
|
|
3851
|
-
data: fulfilledPositions
|
|
3852
|
-
},
|
|
3853
|
-
4 /* COMPLETED */
|
|
3854
|
-
);
|
|
3855
|
-
}
|
|
3856
|
-
return yield this.acpClient.transferFunds(
|
|
3857
|
-
this.id,
|
|
3858
|
-
new FareAmount(totalAmount, this.baseFare),
|
|
3859
|
-
this.clientAddress,
|
|
3860
|
-
new FareAmount(0, this.baseFare),
|
|
3861
|
-
0 /* NO_FEE */,
|
|
3862
|
-
{
|
|
3863
|
-
type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
|
|
3864
|
-
data: fulfilledPositions
|
|
3865
|
-
},
|
|
3866
|
-
4 /* COMPLETED */,
|
|
3867
|
-
expiredAt
|
|
3868
|
-
);
|
|
3869
|
-
});
|
|
3870
|
-
}
|
|
3871
|
-
/**
|
|
3872
|
-
* @deprecated The method should not be used
|
|
3873
|
-
*/
|
|
3874
|
-
confirmJobClosure(memoId, accept, reason) {
|
|
3875
|
-
return __async(this, null, function* () {
|
|
3876
|
-
const memo = this.memos.find((m) => m.id === memoId);
|
|
3877
|
-
if (!memo) {
|
|
3878
|
-
throw new acpError_default("Memo not found");
|
|
3879
|
-
}
|
|
3880
|
-
const payload = tryParseJson(
|
|
3881
|
-
memo.content
|
|
3553
|
+
4 /* COMPLETED */,
|
|
3554
|
+
10 /* PAYABLE_NOTIFICATION */,
|
|
3555
|
+
expiredAt,
|
|
3556
|
+
amount.fare.contractAddress
|
|
3557
|
+
)
|
|
3882
3558
|
);
|
|
3883
|
-
|
|
3884
|
-
throw new acpError_default("Invalid close job and withdraw memo");
|
|
3885
|
-
}
|
|
3886
|
-
yield memo.sign(accept, reason);
|
|
3559
|
+
return yield this.acpContractClient.handleOperation(operations);
|
|
3887
3560
|
});
|
|
3888
3561
|
}
|
|
3889
3562
|
};
|
|
@@ -3928,7 +3601,8 @@ var AcpMemo = class {
|
|
|
3928
3601
|
}
|
|
3929
3602
|
sign(approved, reason) {
|
|
3930
3603
|
return __async(this, null, function* () {
|
|
3931
|
-
|
|
3604
|
+
const payload = this.contractClient.signMemo(this.id, approved, reason);
|
|
3605
|
+
return yield this.contractClient.handleOperation([payload]);
|
|
3932
3606
|
});
|
|
3933
3607
|
}
|
|
3934
3608
|
};
|
|
@@ -3969,7 +3643,7 @@ var AcpJobOffering = class {
|
|
|
3969
3643
|
this.providerAddress,
|
|
3970
3644
|
this.acpContractClient
|
|
3971
3645
|
);
|
|
3972
|
-
const
|
|
3646
|
+
const createJobPayload = [
|
|
3973
3647
|
baseSepoliaAcpConfig.contractAddress,
|
|
3974
3648
|
baseAcpConfig.contractAddress
|
|
3975
3649
|
].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
|
|
@@ -3987,13 +3661,33 @@ var AcpJobOffering = class {
|
|
|
3987
3661
|
fareAmount.fare.contractAddress,
|
|
3988
3662
|
expiredAt
|
|
3989
3663
|
);
|
|
3990
|
-
yield this.acpContractClient.
|
|
3664
|
+
const createJobTxnHash = yield this.acpContractClient.handleOperation([
|
|
3665
|
+
createJobPayload
|
|
3666
|
+
]);
|
|
3667
|
+
const jobId = yield this.acpContractClient.getJobId(
|
|
3668
|
+
createJobTxnHash,
|
|
3669
|
+
this.acpContractClient.walletAddress,
|
|
3670
|
+
this.providerAddress
|
|
3671
|
+
);
|
|
3672
|
+
const payloads = [];
|
|
3673
|
+
const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
|
|
3991
3674
|
jobId,
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3675
|
+
fareAmount.amount,
|
|
3676
|
+
fareAmount.fare.contractAddress
|
|
3677
|
+
);
|
|
3678
|
+
if (setBudgetWithPaymentTokenPayload) {
|
|
3679
|
+
payloads.push(setBudgetWithPaymentTokenPayload);
|
|
3680
|
+
}
|
|
3681
|
+
payloads.push(
|
|
3682
|
+
this.acpContractClient.createMemo(
|
|
3683
|
+
jobId,
|
|
3684
|
+
JSON.stringify(finalServiceRequirement),
|
|
3685
|
+
0 /* MESSAGE */,
|
|
3686
|
+
true,
|
|
3687
|
+
1 /* NEGOTIATION */
|
|
3688
|
+
)
|
|
3996
3689
|
);
|
|
3690
|
+
yield this.acpContractClient.handleOperation(payloads);
|
|
3997
3691
|
return jobId;
|
|
3998
3692
|
});
|
|
3999
3693
|
}
|
|
@@ -4245,12 +3939,16 @@ var AcpClient = class {
|
|
|
4245
3939
|
providerAddress,
|
|
4246
3940
|
this.acpContractClient
|
|
4247
3941
|
);
|
|
4248
|
-
const
|
|
3942
|
+
const defaultEvaluatorAddress = [
|
|
3943
|
+
baseSepoliaAcpConfig.contractAddress,
|
|
3944
|
+
baseAcpConfig.contractAddress
|
|
3945
|
+
].includes(this.acpContractClient.config.contractAddress) && !evaluatorAddress ? this.walletAddress : zeroAddress2;
|
|
3946
|
+
const createJobPayload = [
|
|
4249
3947
|
baseSepoliaAcpConfig.contractAddress,
|
|
4250
3948
|
baseAcpConfig.contractAddress
|
|
4251
3949
|
].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
|
|
4252
3950
|
providerAddress,
|
|
4253
|
-
evaluatorAddress ||
|
|
3951
|
+
evaluatorAddress || defaultEvaluatorAddress,
|
|
4254
3952
|
expiredAt,
|
|
4255
3953
|
fareAmount.fare.contractAddress,
|
|
4256
3954
|
fareAmount.amount,
|
|
@@ -4258,182 +3956,39 @@ var AcpClient = class {
|
|
|
4258
3956
|
) : yield this.acpContractClient.createJobWithAccount(
|
|
4259
3957
|
account.id,
|
|
4260
3958
|
providerAddress,
|
|
4261
|
-
evaluatorAddress ||
|
|
3959
|
+
evaluatorAddress || defaultEvaluatorAddress,
|
|
4262
3960
|
fareAmount.amount,
|
|
4263
3961
|
fareAmount.fare.contractAddress,
|
|
4264
3962
|
expiredAt
|
|
4265
3963
|
);
|
|
4266
|
-
yield this.acpContractClient.
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
return jobId;
|
|
4274
|
-
});
|
|
4275
|
-
}
|
|
4276
|
-
createMemo(jobId, content, nextPhase) {
|
|
4277
|
-
return __async(this, null, function* () {
|
|
4278
|
-
return yield this.acpContractClient.createMemo(
|
|
4279
|
-
jobId,
|
|
4280
|
-
content,
|
|
4281
|
-
0 /* MESSAGE */,
|
|
4282
|
-
false,
|
|
4283
|
-
nextPhase
|
|
4284
|
-
);
|
|
4285
|
-
});
|
|
4286
|
-
}
|
|
4287
|
-
createPayableMemo(jobId, content, amount, recipient, nextPhase, type, expiredAt) {
|
|
4288
|
-
return __async(this, null, function* () {
|
|
4289
|
-
if (type === 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
4290
|
-
yield this.acpContractClient.approveAllowance(
|
|
4291
|
-
amount.amount,
|
|
4292
|
-
amount.fare.contractAddress
|
|
4293
|
-
);
|
|
4294
|
-
}
|
|
4295
|
-
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
|
|
4296
|
-
return yield this.acpContractClient.createPayableMemo(
|
|
4297
|
-
jobId,
|
|
4298
|
-
content,
|
|
4299
|
-
amount.amount,
|
|
4300
|
-
recipient,
|
|
4301
|
-
feeAmount.amount,
|
|
4302
|
-
0 /* NO_FEE */,
|
|
4303
|
-
nextPhase,
|
|
4304
|
-
type,
|
|
4305
|
-
expiredAt,
|
|
4306
|
-
amount.fare.contractAddress
|
|
4307
|
-
);
|
|
4308
|
-
});
|
|
4309
|
-
}
|
|
4310
|
-
respondJob(jobId, memoId, accept, content, reason) {
|
|
4311
|
-
return __async(this, null, function* () {
|
|
4312
|
-
yield this.acpContractClient.signMemo(memoId, accept, reason);
|
|
4313
|
-
if (!accept) {
|
|
4314
|
-
return;
|
|
4315
|
-
}
|
|
4316
|
-
return yield this.acpContractClient.createMemo(
|
|
4317
|
-
jobId,
|
|
4318
|
-
content != null ? content : `Job ${jobId} accepted. ${reason != null ? reason : ""}`,
|
|
4319
|
-
0 /* MESSAGE */,
|
|
4320
|
-
false,
|
|
4321
|
-
2 /* TRANSACTION */
|
|
4322
|
-
);
|
|
4323
|
-
});
|
|
4324
|
-
}
|
|
4325
|
-
payJob(jobId, amountBaseUnit, memoId, reason) {
|
|
4326
|
-
return __async(this, null, function* () {
|
|
4327
|
-
if (amountBaseUnit > BigInt(0)) {
|
|
4328
|
-
yield this.acpContractClient.approveAllowance(amountBaseUnit);
|
|
4329
|
-
}
|
|
4330
|
-
yield this.acpContractClient.signMemo(memoId, true, reason);
|
|
4331
|
-
return yield this.acpContractClient.createMemo(
|
|
4332
|
-
jobId,
|
|
4333
|
-
`Payment made. ${reason != null ? reason : ""}`,
|
|
4334
|
-
0 /* MESSAGE */,
|
|
4335
|
-
false,
|
|
4336
|
-
3 /* EVALUATION */
|
|
3964
|
+
const txHash = yield this.acpContractClient.handleOperation([
|
|
3965
|
+
createJobPayload
|
|
3966
|
+
]);
|
|
3967
|
+
const jobId = yield this.acpContractClient.getJobId(
|
|
3968
|
+
txHash,
|
|
3969
|
+
this.walletAddress,
|
|
3970
|
+
providerAddress
|
|
4337
3971
|
);
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
requestFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
|
|
4341
|
-
return __async(this, null, function* () {
|
|
4342
|
-
return yield this.acpContractClient.createPayableMemo(
|
|
3972
|
+
const payloads = [];
|
|
3973
|
+
const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
|
|
4343
3974
|
jobId,
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
recipient,
|
|
4347
|
-
feeFareAmount.amount,
|
|
4348
|
-
feeType,
|
|
4349
|
-
nextPhase,
|
|
4350
|
-
6 /* PAYABLE_REQUEST */,
|
|
4351
|
-
expiredAt
|
|
3975
|
+
fareAmount.amount,
|
|
3976
|
+
fareAmount.fare.contractAddress
|
|
4352
3977
|
);
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
responseFundsRequest(memoId, accept, amountBaseUnit, reason) {
|
|
4356
|
-
return __async(this, null, function* () {
|
|
4357
|
-
if (!accept) {
|
|
4358
|
-
return yield this.acpContractClient.signMemo(memoId, accept, reason);
|
|
3978
|
+
if (setBudgetWithPaymentTokenPayload) {
|
|
3979
|
+
payloads.push(setBudgetWithPaymentTokenPayload);
|
|
4359
3980
|
}
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
if (transferFareAmount.fare.contractAddress === ethFare.contractAddress) {
|
|
4369
|
-
yield this.acpContractClient.wrapEth(transferFareAmount.amount);
|
|
4370
|
-
transferFareAmount = new FareBigInt(transferFareAmount.amount, wethFare);
|
|
4371
|
-
}
|
|
4372
|
-
if (feeFareAmount.amount > 0 && feeFareAmount.fare.contractAddress !== this.acpContractClient.config.baseFare.contractAddress) {
|
|
4373
|
-
throw new acpError_default("Fee token address is not the same as the base fare");
|
|
4374
|
-
}
|
|
4375
|
-
const isFeeTokenDifferent = feeFareAmount.fare.contractAddress !== transferFareAmount.fare.contractAddress;
|
|
4376
|
-
if (isFeeTokenDifferent) {
|
|
4377
|
-
yield this.acpContractClient.approveAllowance(
|
|
4378
|
-
feeFareAmount.amount,
|
|
4379
|
-
feeFareAmount.fare.contractAddress
|
|
4380
|
-
);
|
|
4381
|
-
}
|
|
4382
|
-
const finalAmount = isFeeTokenDifferent ? transferFareAmount : transferFareAmount.add(feeFareAmount);
|
|
4383
|
-
yield this.acpContractClient.approveAllowance(
|
|
4384
|
-
finalAmount.amount,
|
|
4385
|
-
transferFareAmount.fare.contractAddress
|
|
4386
|
-
);
|
|
4387
|
-
return yield this.acpContractClient.createPayableMemo(
|
|
4388
|
-
jobId,
|
|
4389
|
-
JSON.stringify(reason),
|
|
4390
|
-
transferFareAmount.amount,
|
|
4391
|
-
recipient,
|
|
4392
|
-
feeFareAmount.amount,
|
|
4393
|
-
feeType,
|
|
4394
|
-
nextPhase,
|
|
4395
|
-
8 /* PAYABLE_TRANSFER_ESCROW */,
|
|
4396
|
-
expiredAt,
|
|
4397
|
-
transferFareAmount.fare.contractAddress
|
|
4398
|
-
);
|
|
4399
|
-
});
|
|
4400
|
-
}
|
|
4401
|
-
sendMessage(jobId, message, nextPhase) {
|
|
4402
|
-
return __async(this, null, function* () {
|
|
4403
|
-
return yield this.acpContractClient.createMemo(
|
|
4404
|
-
jobId,
|
|
4405
|
-
JSON.stringify(message),
|
|
4406
|
-
0 /* MESSAGE */,
|
|
4407
|
-
false,
|
|
4408
|
-
nextPhase
|
|
4409
|
-
);
|
|
4410
|
-
});
|
|
4411
|
-
}
|
|
4412
|
-
responseFundsTransfer(memoId, accept, reason) {
|
|
4413
|
-
return __async(this, null, function* () {
|
|
4414
|
-
return yield this.acpContractClient.signMemo(memoId, accept, reason);
|
|
4415
|
-
});
|
|
4416
|
-
}
|
|
4417
|
-
rejectJob(jobId, reason) {
|
|
4418
|
-
return __async(this, null, function* () {
|
|
4419
|
-
return yield this.acpContractClient.createMemo(
|
|
4420
|
-
jobId,
|
|
4421
|
-
`Job ${jobId} rejected. ${reason || ""}`,
|
|
4422
|
-
0 /* MESSAGE */,
|
|
4423
|
-
false,
|
|
4424
|
-
5 /* REJECTED */
|
|
4425
|
-
);
|
|
4426
|
-
});
|
|
4427
|
-
}
|
|
4428
|
-
deliverJob(jobId, deliverable) {
|
|
4429
|
-
return __async(this, null, function* () {
|
|
4430
|
-
return yield this.acpContractClient.createMemo(
|
|
4431
|
-
jobId,
|
|
4432
|
-
preparePayload(deliverable),
|
|
4433
|
-
4 /* OBJECT_URL */,
|
|
4434
|
-
true,
|
|
4435
|
-
4 /* COMPLETED */
|
|
3981
|
+
payloads.push(
|
|
3982
|
+
this.acpContractClient.createMemo(
|
|
3983
|
+
jobId,
|
|
3984
|
+
preparePayload(serviceRequirement),
|
|
3985
|
+
0 /* MESSAGE */,
|
|
3986
|
+
true,
|
|
3987
|
+
1 /* NEGOTIATION */
|
|
3988
|
+
)
|
|
4436
3989
|
);
|
|
3990
|
+
yield this.acpContractClient.handleOperation(payloads);
|
|
3991
|
+
return jobId;
|
|
4437
3992
|
});
|
|
4438
3993
|
}
|
|
4439
3994
|
getActiveJobs(page = 1, pageSize = 10) {
|
|
@@ -4820,14 +4375,14 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
|
|
|
4820
4375
|
return finalMaxFeePerGas;
|
|
4821
4376
|
});
|
|
4822
4377
|
}
|
|
4823
|
-
handleOperation(
|
|
4824
|
-
return __async(this,
|
|
4378
|
+
handleOperation(operations) {
|
|
4379
|
+
return __async(this, null, function* () {
|
|
4825
4380
|
const payload = {
|
|
4826
|
-
uo: {
|
|
4827
|
-
target: contractAddress,
|
|
4828
|
-
data,
|
|
4829
|
-
value
|
|
4830
|
-
},
|
|
4381
|
+
uo: operations.map((op) => ({
|
|
4382
|
+
target: op.contractAddress,
|
|
4383
|
+
data: op.data,
|
|
4384
|
+
value: op.value
|
|
4385
|
+
})),
|
|
4831
4386
|
overrides: {
|
|
4832
4387
|
nonceKey: this.getRandomNonce()
|
|
4833
4388
|
}
|
|
@@ -4884,68 +4439,73 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
|
|
|
4884
4439
|
});
|
|
4885
4440
|
}
|
|
4886
4441
|
createJob(providerAddress, evaluatorAddress, expireAt, paymentTokenAddress, budgetBaseUnit, metadata) {
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
jobId,
|
|
4906
|
-
budgetBaseUnit,
|
|
4907
|
-
paymentTokenAddress
|
|
4908
|
-
);
|
|
4909
|
-
return { txHash: hash, jobId };
|
|
4910
|
-
} catch (error) {
|
|
4911
|
-
throw new acpError_default("Failed to create job", error);
|
|
4912
|
-
}
|
|
4913
|
-
});
|
|
4442
|
+
try {
|
|
4443
|
+
const data = encodeFunctionData2({
|
|
4444
|
+
abi: this.abi,
|
|
4445
|
+
functionName: "createJob",
|
|
4446
|
+
args: [
|
|
4447
|
+
providerAddress,
|
|
4448
|
+
evaluatorAddress,
|
|
4449
|
+
Math.floor(expireAt.getTime() / 1e3)
|
|
4450
|
+
]
|
|
4451
|
+
});
|
|
4452
|
+
const payload = {
|
|
4453
|
+
data,
|
|
4454
|
+
contractAddress: this.contractAddress
|
|
4455
|
+
};
|
|
4456
|
+
return payload;
|
|
4457
|
+
} catch (error) {
|
|
4458
|
+
throw new acpError_default("Failed to create job", error);
|
|
4459
|
+
}
|
|
4914
4460
|
}
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4461
|
+
setBudgetWithPaymentToken(jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
|
|
4462
|
+
try {
|
|
4463
|
+
const data = encodeFunctionData2({
|
|
4464
|
+
abi: this.abi,
|
|
4465
|
+
functionName: "setBudgetWithPaymentToken",
|
|
4466
|
+
args: [jobId, budgetBaseUnit, paymentTokenAddress]
|
|
4467
|
+
});
|
|
4468
|
+
const payload = {
|
|
4469
|
+
data,
|
|
4470
|
+
contractAddress: this.contractAddress
|
|
4471
|
+
};
|
|
4472
|
+
return payload;
|
|
4473
|
+
} catch (error) {
|
|
4474
|
+
throw new acpError_default("Failed to set budget", error);
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
createPayableMemo(jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
|
|
4478
|
+
try {
|
|
4479
|
+
const data = encodeFunctionData2({
|
|
4480
|
+
abi: this.abi,
|
|
4481
|
+
functionName: "createPayableMemo",
|
|
4482
|
+
args: [
|
|
4483
|
+
jobId,
|
|
4484
|
+
content,
|
|
4485
|
+
token,
|
|
4486
|
+
amountBaseUnit,
|
|
4487
|
+
recipient,
|
|
4488
|
+
feeAmountBaseUnit,
|
|
4489
|
+
feeType,
|
|
4490
|
+
type,
|
|
4491
|
+
nextPhase,
|
|
4492
|
+
Math.floor(expiredAt.getTime() / 1e3)
|
|
4493
|
+
]
|
|
4494
|
+
});
|
|
4495
|
+
const payload = {
|
|
4496
|
+
data,
|
|
4497
|
+
contractAddress: this.contractAddress
|
|
4498
|
+
};
|
|
4499
|
+
return payload;
|
|
4500
|
+
} catch (error) {
|
|
4501
|
+
throw new acpError_default("Failed to create payable memo", error);
|
|
4502
|
+
}
|
|
4939
4503
|
}
|
|
4940
4504
|
createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
|
|
4941
|
-
|
|
4942
|
-
throw new acpError_default("Not Supported");
|
|
4943
|
-
});
|
|
4505
|
+
throw new acpError_default("Not Supported");
|
|
4944
4506
|
}
|
|
4945
4507
|
updateAccountMetadata(accountId, metadata) {
|
|
4946
|
-
|
|
4947
|
-
throw new acpError_default("Not Supported");
|
|
4948
|
-
});
|
|
4508
|
+
throw new acpError_default("Not Supported");
|
|
4949
4509
|
}
|
|
4950
4510
|
};
|
|
4951
4511
|
var acpContractClient_default = AcpContractClient;
|
|
@@ -5908,14 +5468,14 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
|
|
|
5908
5468
|
return finalMaxFeePerGas;
|
|
5909
5469
|
});
|
|
5910
5470
|
}
|
|
5911
|
-
handleOperation(
|
|
5912
|
-
return __async(this,
|
|
5471
|
+
handleOperation(operations) {
|
|
5472
|
+
return __async(this, null, function* () {
|
|
5913
5473
|
const payload = {
|
|
5914
|
-
uo: {
|
|
5915
|
-
target: contractAddress,
|
|
5916
|
-
data,
|
|
5917
|
-
value
|
|
5918
|
-
},
|
|
5474
|
+
uo: operations.map((operation) => ({
|
|
5475
|
+
target: operation.contractAddress,
|
|
5476
|
+
data: operation.data,
|
|
5477
|
+
value: operation.value
|
|
5478
|
+
})),
|
|
5919
5479
|
overrides: {
|
|
5920
5480
|
nonceKey: this.getRandomNonce()
|
|
5921
5481
|
}
|
|
@@ -5932,7 +5492,13 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
|
|
|
5932
5492
|
}
|
|
5933
5493
|
const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
|
|
5934
5494
|
yield this.sessionKeyClient.waitForUserOperationTransaction({
|
|
5935
|
-
hash
|
|
5495
|
+
hash,
|
|
5496
|
+
tag: "pending",
|
|
5497
|
+
retries: {
|
|
5498
|
+
intervalMs: 200,
|
|
5499
|
+
multiplier: 1.1,
|
|
5500
|
+
maxRetries: 10
|
|
5501
|
+
}
|
|
5936
5502
|
});
|
|
5937
5503
|
return hash;
|
|
5938
5504
|
} catch (error) {
|
|
@@ -5949,7 +5515,10 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
|
|
|
5949
5515
|
}
|
|
5950
5516
|
getJobId(hash, clientAddress, providerAddress) {
|
|
5951
5517
|
return __async(this, null, function* () {
|
|
5952
|
-
const result = yield this.sessionKeyClient.getUserOperationReceipt(
|
|
5518
|
+
const result = yield this.sessionKeyClient.getUserOperationReceipt(
|
|
5519
|
+
hash,
|
|
5520
|
+
"pending"
|
|
5521
|
+
);
|
|
5953
5522
|
if (!result) {
|
|
5954
5523
|
throw new acpError_default("Failed to get user operation receipt");
|
|
5955
5524
|
}
|