@circle-fin/usdckit 0.22.0 → 0.23.1
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/cjs/abis/EIP2612.d.ts +197 -0
- package/dist/cjs/abis/EIP2612.js +78 -0
- package/dist/cjs/actions/index.d.ts +67 -1
- package/dist/cjs/actions/index.js +7 -0
- package/dist/cjs/actions/index.test.js +4 -0
- package/dist/cjs/actions/permit.d.ts +19 -0
- package/dist/cjs/actions/permit.js +50 -0
- package/dist/cjs/actions/permit.test.d.ts +1 -0
- package/dist/cjs/actions/permit.test.js +652 -0
- package/dist/cjs/actions/signEIP2612Permit.d.ts +130 -0
- package/dist/cjs/actions/signEIP2612Permit.js +128 -0
- package/dist/cjs/actions/signEIP2612Permit.test.d.ts +1 -0
- package/dist/cjs/actions/signEIP2612Permit.test.js +434 -0
- package/dist/cjs/chains/ARC_TESTNET.d.ts +180 -0
- package/dist/cjs/chains/ARC_TESTNET.js +57 -0
- package/dist/cjs/chains/index.d.ts +21 -18
- package/dist/cjs/chains/index.js +27 -25
- package/dist/cjs/chains/index.test.js +1 -0
- package/dist/cjs/client.d.ts +1 -1
- package/dist/cjs/extractChain.d.ts +1492 -1313
- package/dist/cjs/extractChain.test.js +1 -0
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/metadata.js +1 -1
- package/dist/cjs/providers/circle-wallets/actions/createAccount.d.ts +1109 -930
- package/dist/cjs/providers/circle-wallets/actions/createAccount.js +3 -0
- package/dist/cjs/providers/circle-wallets/actions/estimateContractExecutionFee.d.ts +6 -0
- package/dist/cjs/providers/circle-wallets/actions/estimateTransferFee.d.ts +6 -0
- package/dist/cjs/providers/circle-wallets/actions/getAccounts.d.ts +1109 -930
- package/dist/cjs/providers/circle-wallets/index.d.ts +358 -0
- package/dist/cjs/providers/circle-wallets/index.js +2 -0
- package/dist/cjs/providers/circle-wallets/transports/index.d.ts +12 -0
- package/dist/cjs/utils/createConfig.d.ts +1 -1
- package/dist/cjs/utils/createCustomWalletClient.d.ts +1 -1
- package/dist/cjs/utils/getChainContractByAddress.d.ts +1 -1
- package/dist/cjs/utils/getContract.d.ts +8 -8
- package/dist/esm/abis/EIP2612.d.ts +197 -0
- package/dist/esm/abis/EIP2612.js +76 -0
- package/dist/esm/actions/index.d.ts +67 -1
- package/dist/esm/actions/index.js +7 -0
- package/dist/esm/actions/index.test.js +4 -0
- package/dist/esm/actions/permit.d.ts +19 -0
- package/dist/esm/actions/permit.js +44 -0
- package/dist/esm/actions/permit.test.d.ts +1 -0
- package/dist/esm/actions/permit.test.js +650 -0
- package/dist/esm/actions/signEIP2612Permit.d.ts +130 -0
- package/dist/esm/actions/signEIP2612Permit.js +122 -0
- package/dist/esm/actions/signEIP2612Permit.test.d.ts +1 -0
- package/dist/esm/actions/signEIP2612Permit.test.js +432 -0
- package/dist/esm/chains/ARC_TESTNET.d.ts +180 -0
- package/dist/esm/chains/ARC_TESTNET.js +54 -0
- package/dist/esm/chains/index.d.ts +21 -18
- package/dist/esm/chains/index.js +20 -18
- package/dist/esm/chains/index.test.js +1 -0
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/extractChain.d.ts +1492 -1313
- package/dist/esm/extractChain.test.js +2 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/metadata.js +1 -1
- package/dist/esm/providers/circle-wallets/actions/createAccount.d.ts +1109 -930
- package/dist/esm/providers/circle-wallets/actions/createAccount.js +3 -0
- package/dist/esm/providers/circle-wallets/actions/estimateContractExecutionFee.d.ts +6 -0
- package/dist/esm/providers/circle-wallets/actions/estimateTransferFee.d.ts +6 -0
- package/dist/esm/providers/circle-wallets/actions/getAccounts.d.ts +1109 -930
- package/dist/esm/providers/circle-wallets/index.d.ts +358 -0
- package/dist/esm/providers/circle-wallets/index.js +3 -1
- package/dist/esm/providers/circle-wallets/transports/index.d.ts +12 -0
- package/dist/esm/utils/createConfig.d.ts +1 -1
- package/dist/esm/utils/createCustomWalletClient.d.ts +1 -1
- package/dist/esm/utils/getChainContractByAddress.d.ts +1 -1
- package/dist/esm/utils/getContract.d.ts +8 -8
- package/package.json +5 -4
- package/dist/cjs/chains.d.ts +0 -2
- package/dist/cjs/chains.js +0 -12
- package/dist/esm/chains.d.ts +0 -2
- package/dist/esm/chains.js +0 -11
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { signTypedData as _signTypedData } from 'viem/actions';
|
|
2
|
+
import type { Account, Address, BaseUnits, NativeUnits } from '../types.js';
|
|
3
|
+
import type { Chain, Client } from 'viem';
|
|
4
|
+
/**
|
|
5
|
+
* Parameters for the {@link signEIP2612Permit} function.
|
|
6
|
+
*/
|
|
7
|
+
export type SignEIP2612PermitParams = {
|
|
8
|
+
/**
|
|
9
|
+
* The token contract address or contract object that supports EIP-2612 permit functionality.
|
|
10
|
+
*/
|
|
11
|
+
token: Address | {
|
|
12
|
+
address: Address;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The account that owns the tokens and will sign the permit.
|
|
16
|
+
*/
|
|
17
|
+
owner: Address | Account;
|
|
18
|
+
/**
|
|
19
|
+
* The account that will be granted permission to spend the tokens.
|
|
20
|
+
*/
|
|
21
|
+
spender: Address | Account;
|
|
22
|
+
/**
|
|
23
|
+
* The amount of tokens to permit for spending.
|
|
24
|
+
*/
|
|
25
|
+
value: NativeUnits | BaseUnits;
|
|
26
|
+
/**
|
|
27
|
+
* The deadline timestamp for the permit. Defaults to maximum uint256 value.
|
|
28
|
+
*/
|
|
29
|
+
deadline?: bigint;
|
|
30
|
+
/**
|
|
31
|
+
* The blockchain network on which the permit will be created.
|
|
32
|
+
*/
|
|
33
|
+
chain?: Chain;
|
|
34
|
+
/**
|
|
35
|
+
* The name of the token. Defaults to the name of the token contract.
|
|
36
|
+
*/
|
|
37
|
+
name?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The version of the token. Defaults to the version of the token contract. If the token contract does not have a version, defaults to '1'.
|
|
40
|
+
*/
|
|
41
|
+
version?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Return type for the signEIP2612Permit function.
|
|
45
|
+
*/
|
|
46
|
+
export type SignEIP2612PermitReturnType = ReturnType<typeof _signTypedData>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a signed EIP-2612 permit
|
|
49
|
+
*
|
|
50
|
+
* @param client - The client instance.
|
|
51
|
+
* @param params - The permit parameters.
|
|
52
|
+
* @returns An object containing the typed data structure and signature.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* Creating a permit for USDC spending
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const permit = await client.signEIP2612Permit({
|
|
58
|
+
* token: client.chain.contracts.USDC,
|
|
59
|
+
* owner: '0x0000000000000000000000000000000000000000',
|
|
60
|
+
* spender: '0x1111111111111111111111111111111111111111',
|
|
61
|
+
* value: 1000000n, // 1 USDC (6 decimals)
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* Creating a permit with custom deadline
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const permit = await client.signEIP2612Permit({
|
|
69
|
+
* token: '0x...',
|
|
70
|
+
* owner: account1,
|
|
71
|
+
* spender: account2,
|
|
72
|
+
* value: '100',
|
|
73
|
+
* deadline: BigInt(Math.floor(Date.now() / 1000) + 3600), // 1 hour from now
|
|
74
|
+
* })
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function signEIP2612Permit(client: Client, params: SignEIP2612PermitParams): Promise<{
|
|
78
|
+
typedData: {
|
|
79
|
+
readonly types: {
|
|
80
|
+
readonly EIP712Domain: readonly [{
|
|
81
|
+
readonly name: "name";
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
}, {
|
|
84
|
+
readonly name: "version";
|
|
85
|
+
readonly type: "string";
|
|
86
|
+
}, {
|
|
87
|
+
readonly name: "chainId";
|
|
88
|
+
readonly type: "uint256";
|
|
89
|
+
}, {
|
|
90
|
+
readonly name: "verifyingContract";
|
|
91
|
+
readonly type: "address";
|
|
92
|
+
}];
|
|
93
|
+
readonly Permit: readonly [{
|
|
94
|
+
readonly name: "owner";
|
|
95
|
+
readonly type: "address";
|
|
96
|
+
}, {
|
|
97
|
+
readonly name: "spender";
|
|
98
|
+
readonly type: "address";
|
|
99
|
+
}, {
|
|
100
|
+
readonly name: "value";
|
|
101
|
+
readonly type: "uint256";
|
|
102
|
+
}, {
|
|
103
|
+
readonly name: "nonce";
|
|
104
|
+
readonly type: "uint256";
|
|
105
|
+
}, {
|
|
106
|
+
readonly name: "deadline";
|
|
107
|
+
readonly type: "uint256";
|
|
108
|
+
}];
|
|
109
|
+
};
|
|
110
|
+
readonly primaryType: "Permit";
|
|
111
|
+
readonly domain: {
|
|
112
|
+
readonly name: string;
|
|
113
|
+
readonly version: string;
|
|
114
|
+
readonly chainId: bigint;
|
|
115
|
+
readonly verifyingContract: `0x${string}`;
|
|
116
|
+
};
|
|
117
|
+
readonly message: {
|
|
118
|
+
readonly owner: `0x${string}`;
|
|
119
|
+
readonly spender: `0x${string}`;
|
|
120
|
+
readonly value: bigint;
|
|
121
|
+
readonly nonce: bigint;
|
|
122
|
+
readonly deadline: bigint;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
signature: `0x${string}`;
|
|
126
|
+
r: `0x${string}`;
|
|
127
|
+
s: `0x${string}`;
|
|
128
|
+
yParity: number;
|
|
129
|
+
v: number;
|
|
130
|
+
}>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, Circle Internet Group, Inc.
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// Circle Internet Group, Inc. CONFIDENTIAL
|
|
6
|
+
//
|
|
7
|
+
// This file includes unpublished proprietary source code of Circle Internet
|
|
8
|
+
// Group, Inc. The copyright notice above does not
|
|
9
|
+
// evidence any actual or intended publication of such source code. Disclosure
|
|
10
|
+
// of this source code or any related proprietary information is strictly
|
|
11
|
+
// prohibited without the express written permission of Circle Internet Group, Inc.
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.signEIP2612Permit = signEIP2612Permit;
|
|
17
|
+
const viem_1 = require("viem");
|
|
18
|
+
const actions_1 = require("viem/actions");
|
|
19
|
+
const utils_1 = require("viem/utils");
|
|
20
|
+
const EIP2612_js_1 = __importDefault(require("../abis/EIP2612.js"));
|
|
21
|
+
const getClient_js_1 = require("../utils/getClient.js");
|
|
22
|
+
const parseAccount_js_1 = require("../utils/parseAccount.js");
|
|
23
|
+
const parseAddress_js_1 = require("../utils/parseAddress.js");
|
|
24
|
+
const parseUnits_js_1 = require("../utils/parseUnits.js");
|
|
25
|
+
const raise_js_1 = require("../utils/raise.js");
|
|
26
|
+
/**
|
|
27
|
+
* Creates a signed EIP-2612 permit
|
|
28
|
+
*
|
|
29
|
+
* @param client - The client instance.
|
|
30
|
+
* @param params - The permit parameters.
|
|
31
|
+
* @returns An object containing the typed data structure and signature.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* Creating a permit for USDC spending
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const permit = await client.signEIP2612Permit({
|
|
37
|
+
* token: client.chain.contracts.USDC,
|
|
38
|
+
* owner: '0x0000000000000000000000000000000000000000',
|
|
39
|
+
* spender: '0x1111111111111111111111111111111111111111',
|
|
40
|
+
* value: 1000000n, // 1 USDC (6 decimals)
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* Creating a permit with custom deadline
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const permit = await client.signEIP2612Permit({
|
|
48
|
+
* token: '0x...',
|
|
49
|
+
* owner: account1,
|
|
50
|
+
* spender: account2,
|
|
51
|
+
* value: '100',
|
|
52
|
+
* deadline: BigInt(Math.floor(Date.now() / 1000) + 3600), // 1 hour from now
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async function signEIP2612Permit(client, params) {
|
|
57
|
+
const { token: _token, owner: _owner, spender: _spender, value: _value, deadline = viem_1.maxUint256, chain = client.chain, name: _name, version: _version, } = params;
|
|
58
|
+
const _client = (0, getClient_js_1.getClient)(client, chain);
|
|
59
|
+
const signTypedData = (0, utils_1.getAction)(_client, actions_1.signTypedData, 'signTypedData');
|
|
60
|
+
// Parse addresses and accounts
|
|
61
|
+
const { address: verifyingContractAddress } = (0, parseAddress_js_1.parseAddress)(_token);
|
|
62
|
+
const owner = (0, parseAccount_js_1.parseAccount)(_owner, { chain });
|
|
63
|
+
const spender = (0, parseAccount_js_1.parseAccount)(_spender, { chain });
|
|
64
|
+
// Create contract instance with EIP-2612 ABI
|
|
65
|
+
const verifyingContract = (0, viem_1.getContract)({
|
|
66
|
+
address: verifyingContractAddress,
|
|
67
|
+
abi: EIP2612_js_1.default,
|
|
68
|
+
client,
|
|
69
|
+
});
|
|
70
|
+
// Fetch token metadata and owner's nonce
|
|
71
|
+
const [name, version, nonce, decimals] = await Promise.all([
|
|
72
|
+
_name ?? verifyingContract.read.name(),
|
|
73
|
+
// Default version to '1' if `version()` fails
|
|
74
|
+
_version ?? verifyingContract.read.version().catch(() => '1'),
|
|
75
|
+
verifyingContract.read.nonces([owner.address]),
|
|
76
|
+
verifyingContract.read.decimals(),
|
|
77
|
+
]);
|
|
78
|
+
const value = (0, parseUnits_js_1.parseUnits)(_value, decimals);
|
|
79
|
+
const typedData = {
|
|
80
|
+
types: {
|
|
81
|
+
EIP712Domain: [
|
|
82
|
+
{ name: 'name', type: 'string' },
|
|
83
|
+
{ name: 'version', type: 'string' },
|
|
84
|
+
{ name: 'chainId', type: 'uint256' },
|
|
85
|
+
{ name: 'verifyingContract', type: 'address' },
|
|
86
|
+
],
|
|
87
|
+
Permit: [
|
|
88
|
+
{ name: 'owner', type: 'address' },
|
|
89
|
+
{ name: 'spender', type: 'address' },
|
|
90
|
+
{ name: 'value', type: 'uint256' },
|
|
91
|
+
{ name: 'nonce', type: 'uint256' },
|
|
92
|
+
{ name: 'deadline', type: 'uint256' },
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
primaryType: 'Permit',
|
|
96
|
+
domain: {
|
|
97
|
+
name,
|
|
98
|
+
version,
|
|
99
|
+
chainId: BigInt(chain.id),
|
|
100
|
+
verifyingContract: verifyingContract.address,
|
|
101
|
+
},
|
|
102
|
+
message: {
|
|
103
|
+
owner: owner.address,
|
|
104
|
+
spender: spender.address,
|
|
105
|
+
value,
|
|
106
|
+
nonce,
|
|
107
|
+
deadline,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
const signature = await signTypedData({
|
|
111
|
+
...typedData,
|
|
112
|
+
account: owner,
|
|
113
|
+
});
|
|
114
|
+
const { r, s, v, yParity } = (0, viem_1.parseSignature)(signature);
|
|
115
|
+
return {
|
|
116
|
+
typedData,
|
|
117
|
+
signature,
|
|
118
|
+
r,
|
|
119
|
+
s,
|
|
120
|
+
yParity,
|
|
121
|
+
// Backfill `v` from `yParity` if not present
|
|
122
|
+
// REF: https://github.com/ethereum/go-ethereum/blob/1487a8577d1566497e161a04f8cee3204d4b3d36/core/types/transaction_marshalling.go#L63-L79
|
|
123
|
+
v: Number(v ??
|
|
124
|
+
(yParity === 0 ? 27n : undefined) ??
|
|
125
|
+
(yParity === 1 ? 28n : undefined) ??
|
|
126
|
+
(0, raise_js_1.raise)(new Error('v is missing and yParity must be 0 or 1'))),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|