@axonfi/sdk 0.9.0 → 0.11.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 +71 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -84
- package/dist/index.d.ts +33 -84
- package/dist/index.js +71 -100
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -64,10 +64,12 @@ var EXPLORER_ADDR = {
|
|
|
64
64
|
var DEFAULT_DEADLINE_SECONDS = 300;
|
|
65
65
|
var WINDOW = {
|
|
66
66
|
ONE_HOUR: 3600n,
|
|
67
|
+
THREE_HOURS: 10800n,
|
|
67
68
|
ONE_DAY: 86400n,
|
|
68
69
|
ONE_WEEK: 604800n,
|
|
69
70
|
THIRTY_DAYS: 2592000n
|
|
70
71
|
};
|
|
72
|
+
var ALLOWED_WINDOWS = new Set(Object.values(WINDOW));
|
|
71
73
|
var PaymentErrorCode = {
|
|
72
74
|
/** Payment destination is the vault itself */
|
|
73
75
|
SELF_PAYMENT: "SELF_PAYMENT",
|
|
@@ -670,26 +672,6 @@ var AxonVaultAbi = [
|
|
|
670
672
|
"name": "signature",
|
|
671
673
|
"type": "bytes",
|
|
672
674
|
"internalType": "bytes"
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
"name": "fromToken",
|
|
676
|
-
"type": "address",
|
|
677
|
-
"internalType": "address"
|
|
678
|
-
},
|
|
679
|
-
{
|
|
680
|
-
"name": "maxFromAmount",
|
|
681
|
-
"type": "uint256",
|
|
682
|
-
"internalType": "uint256"
|
|
683
|
-
},
|
|
684
|
-
{
|
|
685
|
-
"name": "swapRouter",
|
|
686
|
-
"type": "address",
|
|
687
|
-
"internalType": "address"
|
|
688
|
-
},
|
|
689
|
-
{
|
|
690
|
-
"name": "swapCalldata",
|
|
691
|
-
"type": "bytes",
|
|
692
|
-
"internalType": "bytes"
|
|
693
675
|
}
|
|
694
676
|
],
|
|
695
677
|
"outputs": [],
|
|
@@ -755,26 +737,6 @@ var AxonVaultAbi = [
|
|
|
755
737
|
"name": "callData",
|
|
756
738
|
"type": "bytes",
|
|
757
739
|
"internalType": "bytes"
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
"name": "fromToken",
|
|
761
|
-
"type": "address",
|
|
762
|
-
"internalType": "address"
|
|
763
|
-
},
|
|
764
|
-
{
|
|
765
|
-
"name": "maxFromAmount",
|
|
766
|
-
"type": "uint256",
|
|
767
|
-
"internalType": "uint256"
|
|
768
|
-
},
|
|
769
|
-
{
|
|
770
|
-
"name": "swapRouter",
|
|
771
|
-
"type": "address",
|
|
772
|
-
"internalType": "address"
|
|
773
|
-
},
|
|
774
|
-
{
|
|
775
|
-
"name": "swapCalldata",
|
|
776
|
-
"type": "bytes",
|
|
777
|
-
"internalType": "bytes"
|
|
778
740
|
}
|
|
779
741
|
],
|
|
780
742
|
"outputs": [
|
|
@@ -2231,55 +2193,6 @@ var AxonVaultAbi = [
|
|
|
2231
2193
|
],
|
|
2232
2194
|
"anonymous": false
|
|
2233
2195
|
},
|
|
2234
|
-
{
|
|
2235
|
-
"type": "event",
|
|
2236
|
-
"name": "SwapPaymentExecuted",
|
|
2237
|
-
"inputs": [
|
|
2238
|
-
{
|
|
2239
|
-
"name": "bot",
|
|
2240
|
-
"type": "address",
|
|
2241
|
-
"indexed": true,
|
|
2242
|
-
"internalType": "address"
|
|
2243
|
-
},
|
|
2244
|
-
{
|
|
2245
|
-
"name": "to",
|
|
2246
|
-
"type": "address",
|
|
2247
|
-
"indexed": true,
|
|
2248
|
-
"internalType": "address"
|
|
2249
|
-
},
|
|
2250
|
-
{
|
|
2251
|
-
"name": "fromToken",
|
|
2252
|
-
"type": "address",
|
|
2253
|
-
"indexed": false,
|
|
2254
|
-
"internalType": "address"
|
|
2255
|
-
},
|
|
2256
|
-
{
|
|
2257
|
-
"name": "toToken",
|
|
2258
|
-
"type": "address",
|
|
2259
|
-
"indexed": false,
|
|
2260
|
-
"internalType": "address"
|
|
2261
|
-
},
|
|
2262
|
-
{
|
|
2263
|
-
"name": "fromAmount",
|
|
2264
|
-
"type": "uint256",
|
|
2265
|
-
"indexed": false,
|
|
2266
|
-
"internalType": "uint256"
|
|
2267
|
-
},
|
|
2268
|
-
{
|
|
2269
|
-
"name": "toAmount",
|
|
2270
|
-
"type": "uint256",
|
|
2271
|
-
"indexed": false,
|
|
2272
|
-
"internalType": "uint256"
|
|
2273
|
-
},
|
|
2274
|
-
{
|
|
2275
|
-
"name": "ref",
|
|
2276
|
-
"type": "bytes32",
|
|
2277
|
-
"indexed": false,
|
|
2278
|
-
"internalType": "bytes32"
|
|
2279
|
-
}
|
|
2280
|
-
],
|
|
2281
|
-
"anonymous": false
|
|
2282
|
-
},
|
|
2283
2196
|
{
|
|
2284
2197
|
"type": "event",
|
|
2285
2198
|
"name": "Unpaused",
|
|
@@ -2422,22 +2335,22 @@ var AxonVaultAbi = [
|
|
|
2422
2335
|
},
|
|
2423
2336
|
{
|
|
2424
2337
|
"type": "error",
|
|
2425
|
-
"name": "
|
|
2338
|
+
"name": "IntentAlreadyUsed",
|
|
2426
2339
|
"inputs": []
|
|
2427
2340
|
},
|
|
2428
2341
|
{
|
|
2429
2342
|
"type": "error",
|
|
2430
|
-
"name": "
|
|
2343
|
+
"name": "InvalidInitialization",
|
|
2431
2344
|
"inputs": []
|
|
2432
2345
|
},
|
|
2433
2346
|
{
|
|
2434
2347
|
"type": "error",
|
|
2435
|
-
"name": "
|
|
2348
|
+
"name": "InvalidSignature",
|
|
2436
2349
|
"inputs": []
|
|
2437
2350
|
},
|
|
2438
2351
|
{
|
|
2439
2352
|
"type": "error",
|
|
2440
|
-
"name": "
|
|
2353
|
+
"name": "InvalidSpendingWindow",
|
|
2441
2354
|
"inputs": []
|
|
2442
2355
|
},
|
|
2443
2356
|
{
|
|
@@ -3248,6 +3161,12 @@ function createAxonWalletClient(privateKey, chainId) {
|
|
|
3248
3161
|
var USDC_DECIMALS = 6n;
|
|
3249
3162
|
var USDC_UNIT = 10n ** USDC_DECIMALS;
|
|
3250
3163
|
function toBotConfigParams(input) {
|
|
3164
|
+
for (const sl of input.spendingLimits) {
|
|
3165
|
+
if (!ALLOWED_WINDOWS.has(BigInt(sl.windowSeconds))) {
|
|
3166
|
+
const allowed = [...ALLOWED_WINDOWS].map((w) => `${Number(w)}s`).join(", ");
|
|
3167
|
+
throw new Error(`Invalid spending window: ${sl.windowSeconds}s. Allowed values: ${allowed}. Use WINDOW constants.`);
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3251
3170
|
return {
|
|
3252
3171
|
maxPerTxAmount: BigInt(Math.round(input.maxPerTxAmount * Number(USDC_UNIT))),
|
|
3253
3172
|
maxRebalanceAmount: BigInt(Math.round(input.maxRebalanceAmount * Number(USDC_UNIT))),
|
|
@@ -3973,11 +3892,30 @@ var AxonClient = class {
|
|
|
3973
3892
|
* - `"approved"`: fast path — txHash available immediately
|
|
3974
3893
|
* - `"pending_review"`: AI scan or human review in progress — poll for status
|
|
3975
3894
|
* - `"rejected"`: payment was rejected — reason field explains why
|
|
3895
|
+
*
|
|
3896
|
+
* If the vault doesn't hold enough of the payment token, the relayer returns
|
|
3897
|
+
* `errorCode: 'SWAP_REQUIRED'`. The SDK automatically signs a SwapIntent and
|
|
3898
|
+
* resubmits the payment with swap fields — no action needed from the caller.
|
|
3976
3899
|
*/
|
|
3977
3900
|
async pay(input) {
|
|
3978
3901
|
const intent = this._buildPaymentIntent(input);
|
|
3979
3902
|
const signature = await signPayment(this.walletClient, this.vaultAddress, this.chainId, intent);
|
|
3980
|
-
|
|
3903
|
+
const result = await this._submitPayment(intent, signature, input);
|
|
3904
|
+
if (result.status === "rejected" && result.errorCode === "SWAP_REQUIRED") {
|
|
3905
|
+
const swapIntent = {
|
|
3906
|
+
bot: this.botAddress,
|
|
3907
|
+
toToken: intent.token,
|
|
3908
|
+
// swap TO the payment token
|
|
3909
|
+
minToAmount: intent.amount,
|
|
3910
|
+
// need at least the payment amount
|
|
3911
|
+
deadline: intent.deadline,
|
|
3912
|
+
// same deadline
|
|
3913
|
+
ref: intent.ref
|
|
3914
|
+
};
|
|
3915
|
+
const swapSig = await signSwapIntent(this.walletClient, this.vaultAddress, this.chainId, swapIntent);
|
|
3916
|
+
return this._submitPaymentWithSwap(intent, signature, input, swapIntent, swapSig);
|
|
3917
|
+
}
|
|
3918
|
+
return result;
|
|
3981
3919
|
}
|
|
3982
3920
|
// ============================================================================
|
|
3983
3921
|
// execute()
|
|
@@ -3988,6 +3926,12 @@ var AxonClient = class {
|
|
|
3988
3926
|
* The vault approves `token` to `protocol`, calls it with `callData`,
|
|
3989
3927
|
* then revokes the approval. Tokens stay in the vault or go to the protocol
|
|
3990
3928
|
* as specified by the calldata.
|
|
3929
|
+
*
|
|
3930
|
+
* **Approval rules for default tokens** (USDC, WETH, etc.): when calling
|
|
3931
|
+
* `approve()` on a default token, the spender must be an approved protocol
|
|
3932
|
+
* or swap router — the contract rejects arbitrary addresses. The approve
|
|
3933
|
+
* amount is capped by the bot's `maxPerTxAmount` and counts toward
|
|
3934
|
+
* spending limits.
|
|
3991
3935
|
*/
|
|
3992
3936
|
async execute(input) {
|
|
3993
3937
|
const intent = this._buildExecuteIntent(input);
|
|
@@ -4250,6 +4194,38 @@ Timestamp: ${timestamp}`;
|
|
|
4250
4194
|
ref: this._resolveRef(input.memo, input.ref)
|
|
4251
4195
|
};
|
|
4252
4196
|
}
|
|
4197
|
+
async _submitPaymentWithSwap(intent, signature, input, swapIntent, swapSignature) {
|
|
4198
|
+
const idempotencyKey = generateUuid();
|
|
4199
|
+
const body = {
|
|
4200
|
+
// Routing
|
|
4201
|
+
chainId: this.chainId,
|
|
4202
|
+
vaultAddress: this.vaultAddress,
|
|
4203
|
+
// Flat intent fields (matches relayer DTO)
|
|
4204
|
+
bot: intent.bot,
|
|
4205
|
+
to: intent.to,
|
|
4206
|
+
token: intent.token,
|
|
4207
|
+
amount: intent.amount.toString(),
|
|
4208
|
+
deadline: intent.deadline.toString(),
|
|
4209
|
+
ref: intent.ref,
|
|
4210
|
+
signature,
|
|
4211
|
+
// Swap fields
|
|
4212
|
+
swapSignature,
|
|
4213
|
+
swapToToken: swapIntent.toToken,
|
|
4214
|
+
swapMinToAmount: swapIntent.minToAmount.toString(),
|
|
4215
|
+
swapDeadline: swapIntent.deadline.toString(),
|
|
4216
|
+
swapRef: swapIntent.ref,
|
|
4217
|
+
// Off-chain metadata
|
|
4218
|
+
idempotencyKey,
|
|
4219
|
+
...input.memo !== void 0 && { memo: input.memo },
|
|
4220
|
+
...input.resourceUrl !== void 0 && { resourceUrl: input.resourceUrl },
|
|
4221
|
+
...input.invoiceId !== void 0 && { invoiceId: input.invoiceId },
|
|
4222
|
+
...input.orderId !== void 0 && { orderId: input.orderId },
|
|
4223
|
+
...input.recipientLabel !== void 0 && { recipientLabel: input.recipientLabel },
|
|
4224
|
+
...input.metadata !== void 0 && { metadata: input.metadata },
|
|
4225
|
+
...input.x402Funding !== void 0 && { x402Funding: input.x402Funding }
|
|
4226
|
+
};
|
|
4227
|
+
return this._post(RELAYER_API.PAYMENTS, idempotencyKey, body);
|
|
4228
|
+
}
|
|
4253
4229
|
async _submitPayment(intent, signature, input) {
|
|
4254
4230
|
const idempotencyKey = input.idempotencyKey ?? generateUuid();
|
|
4255
4231
|
const body = {
|
|
@@ -4278,8 +4254,6 @@ Timestamp: ${timestamp}`;
|
|
|
4278
4254
|
}
|
|
4279
4255
|
async _submitExecute(intent, signature, input) {
|
|
4280
4256
|
const idempotencyKey = input.idempotencyKey ?? generateUuid();
|
|
4281
|
-
const fromToken = input.fromToken !== void 0 ? resolveToken(input.fromToken, this.chainId) : void 0;
|
|
4282
|
-
const maxFromAmount = input.maxFromAmount !== void 0 ? parseAmount(input.maxFromAmount, input.fromToken ?? input.tokens?.[0] ?? "USDC", this.chainId) : void 0;
|
|
4283
4257
|
const body = {
|
|
4284
4258
|
chainId: this.chainId,
|
|
4285
4259
|
vaultAddress: this.vaultAddress,
|
|
@@ -4295,9 +4269,6 @@ Timestamp: ${timestamp}`;
|
|
|
4295
4269
|
signature,
|
|
4296
4270
|
// Protocol calldata
|
|
4297
4271
|
callData: input.callData,
|
|
4298
|
-
// Optional pre-swap
|
|
4299
|
-
...fromToken !== void 0 && { fromToken },
|
|
4300
|
-
...maxFromAmount !== void 0 && { maxFromAmount: maxFromAmount.toString() },
|
|
4301
4272
|
// Off-chain metadata
|
|
4302
4273
|
idempotencyKey,
|
|
4303
4274
|
...input.memo !== void 0 && { memo: input.memo },
|
|
@@ -4987,6 +4958,6 @@ var AxonRegistryAbi = [
|
|
|
4987
4958
|
}
|
|
4988
4959
|
];
|
|
4989
4960
|
|
|
4990
|
-
export { AxonClient, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, DEFAULT_DEADLINE_SECONDS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, KNOWN_TOKENS, NATIVE_ETH, PAYMENT_INTENT_TYPEHASH, PERMIT2_ADDRESS, PaymentErrorCode, RELAYER_API, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, Token, USDC, USDC_EIP712_DOMAIN, WINDOW, WITNESS_TYPE_STRING, X402_PROXY_ADDRESS, addBot, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, deposit, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDefaultApprovedTokens, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isErc1271BotsEnabled, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, predictVaultAddress, randomNonce, randomPermit2Nonce, removeBot, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization, toBotConfigParams, updateBotConfig };
|
|
4961
|
+
export { ALLOWED_WINDOWS, AxonClient, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, DEFAULT_DEADLINE_SECONDS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, KNOWN_TOKENS, NATIVE_ETH, PAYMENT_INTENT_TYPEHASH, PERMIT2_ADDRESS, PaymentErrorCode, RELAYER_API, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, Token, USDC, USDC_EIP712_DOMAIN, WINDOW, WITNESS_TYPE_STRING, X402_PROXY_ADDRESS, addBot, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, deposit, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDefaultApprovedTokens, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isErc1271BotsEnabled, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, predictVaultAddress, randomNonce, randomPermit2Nonce, removeBot, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization, toBotConfigParams, updateBotConfig };
|
|
4991
4962
|
//# sourceMappingURL=index.js.map
|
|
4992
4963
|
//# sourceMappingURL=index.js.map
|