@axonfi/sdk 0.9.0 → 0.10.0
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.cjs +52 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +52 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3975,11 +3975,30 @@ var AxonClient = class {
|
|
|
3975
3975
|
* - `"approved"`: fast path — txHash available immediately
|
|
3976
3976
|
* - `"pending_review"`: AI scan or human review in progress — poll for status
|
|
3977
3977
|
* - `"rejected"`: payment was rejected — reason field explains why
|
|
3978
|
+
*
|
|
3979
|
+
* If the vault doesn't hold enough of the payment token, the relayer returns
|
|
3980
|
+
* `errorCode: 'SWAP_REQUIRED'`. The SDK automatically signs a SwapIntent and
|
|
3981
|
+
* resubmits the payment with swap fields — no action needed from the caller.
|
|
3978
3982
|
*/
|
|
3979
3983
|
async pay(input) {
|
|
3980
3984
|
const intent = this._buildPaymentIntent(input);
|
|
3981
3985
|
const signature = await signPayment(this.walletClient, this.vaultAddress, this.chainId, intent);
|
|
3982
|
-
|
|
3986
|
+
const result = await this._submitPayment(intent, signature, input);
|
|
3987
|
+
if (result.status === "rejected" && result.errorCode === "SWAP_REQUIRED") {
|
|
3988
|
+
const swapIntent = {
|
|
3989
|
+
bot: this.botAddress,
|
|
3990
|
+
toToken: intent.token,
|
|
3991
|
+
// swap TO the payment token
|
|
3992
|
+
minToAmount: intent.amount,
|
|
3993
|
+
// need at least the payment amount
|
|
3994
|
+
deadline: intent.deadline,
|
|
3995
|
+
// same deadline
|
|
3996
|
+
ref: intent.ref
|
|
3997
|
+
};
|
|
3998
|
+
const swapSig = await signSwapIntent(this.walletClient, this.vaultAddress, this.chainId, swapIntent);
|
|
3999
|
+
return this._submitPaymentWithSwap(intent, signature, input, swapIntent, swapSig);
|
|
4000
|
+
}
|
|
4001
|
+
return result;
|
|
3983
4002
|
}
|
|
3984
4003
|
// ============================================================================
|
|
3985
4004
|
// execute()
|
|
@@ -4252,6 +4271,38 @@ Timestamp: ${timestamp}`;
|
|
|
4252
4271
|
ref: this._resolveRef(input.memo, input.ref)
|
|
4253
4272
|
};
|
|
4254
4273
|
}
|
|
4274
|
+
async _submitPaymentWithSwap(intent, signature, input, swapIntent, swapSignature) {
|
|
4275
|
+
const idempotencyKey = generateUuid();
|
|
4276
|
+
const body = {
|
|
4277
|
+
// Routing
|
|
4278
|
+
chainId: this.chainId,
|
|
4279
|
+
vaultAddress: this.vaultAddress,
|
|
4280
|
+
// Flat intent fields (matches relayer DTO)
|
|
4281
|
+
bot: intent.bot,
|
|
4282
|
+
to: intent.to,
|
|
4283
|
+
token: intent.token,
|
|
4284
|
+
amount: intent.amount.toString(),
|
|
4285
|
+
deadline: intent.deadline.toString(),
|
|
4286
|
+
ref: intent.ref,
|
|
4287
|
+
signature,
|
|
4288
|
+
// Swap fields
|
|
4289
|
+
swapSignature,
|
|
4290
|
+
swapToToken: swapIntent.toToken,
|
|
4291
|
+
swapMinToAmount: swapIntent.minToAmount.toString(),
|
|
4292
|
+
swapDeadline: swapIntent.deadline.toString(),
|
|
4293
|
+
swapRef: swapIntent.ref,
|
|
4294
|
+
// Off-chain metadata
|
|
4295
|
+
idempotencyKey,
|
|
4296
|
+
...input.memo !== void 0 && { memo: input.memo },
|
|
4297
|
+
...input.resourceUrl !== void 0 && { resourceUrl: input.resourceUrl },
|
|
4298
|
+
...input.invoiceId !== void 0 && { invoiceId: input.invoiceId },
|
|
4299
|
+
...input.orderId !== void 0 && { orderId: input.orderId },
|
|
4300
|
+
...input.recipientLabel !== void 0 && { recipientLabel: input.recipientLabel },
|
|
4301
|
+
...input.metadata !== void 0 && { metadata: input.metadata },
|
|
4302
|
+
...input.x402Funding !== void 0 && { x402Funding: input.x402Funding }
|
|
4303
|
+
};
|
|
4304
|
+
return this._post(RELAYER_API.PAYMENTS, idempotencyKey, body);
|
|
4305
|
+
}
|
|
4255
4306
|
async _submitPayment(intent, signature, input) {
|
|
4256
4307
|
const idempotencyKey = input.idempotencyKey ?? generateUuid();
|
|
4257
4308
|
const body = {
|
|
@@ -4280,8 +4331,6 @@ Timestamp: ${timestamp}`;
|
|
|
4280
4331
|
}
|
|
4281
4332
|
async _submitExecute(intent, signature, input) {
|
|
4282
4333
|
const idempotencyKey = input.idempotencyKey ?? generateUuid();
|
|
4283
|
-
const fromToken = input.fromToken !== void 0 ? resolveToken(input.fromToken, this.chainId) : void 0;
|
|
4284
|
-
const maxFromAmount = input.maxFromAmount !== void 0 ? parseAmount(input.maxFromAmount, input.fromToken ?? input.tokens?.[0] ?? "USDC", this.chainId) : void 0;
|
|
4285
4334
|
const body = {
|
|
4286
4335
|
chainId: this.chainId,
|
|
4287
4336
|
vaultAddress: this.vaultAddress,
|
|
@@ -4297,9 +4346,6 @@ Timestamp: ${timestamp}`;
|
|
|
4297
4346
|
signature,
|
|
4298
4347
|
// Protocol calldata
|
|
4299
4348
|
callData: input.callData,
|
|
4300
|
-
// Optional pre-swap
|
|
4301
|
-
...fromToken !== void 0 && { fromToken },
|
|
4302
|
-
...maxFromAmount !== void 0 && { maxFromAmount: maxFromAmount.toString() },
|
|
4303
4349
|
// Off-chain metadata
|
|
4304
4350
|
idempotencyKey,
|
|
4305
4351
|
...input.memo !== void 0 && { memo: input.memo },
|