Skip to content

Commit 00b4e83

Browse files
🔄 synced file(s) with circlefin/modularwallets-web-sdk-internal (#7)
synced local file(s) with [circlefin/modularwallets-web-sdk-internal](https://github.com/circlefin/modularwallets-web-sdk-internal). <details> <summary>Changed files</summary> <ul> <li>synced local directory <code>packages/</code> with remote directory <code>packages/</code></li> </ul> </details> --- This PR was created automatically by the [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action) workflow run [#13492226453](https://github.com/circlefin/modularwallets-web-sdk-internal/actions/runs/13492226453)
1 parent 6d42e65 commit 00b4e83

File tree

13 files changed

+238
-1
lines changed

13 files changed

+238
-1
lines changed

‎packages/w3s-web-core-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@circle-fin/modular-wallets-core",
33
"description": "Serverless Typescript SDK",
4-
"version": "1.0.3",
4+
"version": "1.0.4",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",
77
"types": "./dist/index.d.ts",

‎packages/w3s-web-core-sdk/src/__mocks__/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
export * from './accounts'
2020
export * from './clients'
2121
export * from './providers'
22+
export * from './utils'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at.
9+
*
10+
* Http://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import type { Hex } from 'viem'
20+
21+
/**
22+
* Mocks for the utility function - encodeTransfer to address parameter.
23+
*/
24+
export const MockRecipientAddress: Hex =
25+
'0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
26+
27+
/**
28+
* Mocks for the utility function - encodeTransfer response.
29+
*/
30+
export const MockEncodedPredefinedTokenTransferResult = {
31+
data: '0xa9059cbb000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000000000000000064',
32+
to: '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582',
33+
}
34+
35+
/**
36+
* Mocks for the utility function - encodeTransfer response.
37+
*/
38+
export const MockEncodedERC20TransferResult = {
39+
data: '0xa9059cbb000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e8',
40+
to: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
41+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at.
9+
*
10+
* Http://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
export * from './encodeTransfer.Mock'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at.
9+
*
10+
* Http://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
export * from './encoding'
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at.
9+
*
10+
* Http://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import {
20+
MockEncodedERC20TransferResult,
21+
MockEncodedPredefinedTokenTransferResult,
22+
MockRecipientAddress,
23+
} from '../../../__mocks__'
24+
import { ContractAddress } from '../../../constants'
25+
import { encodeTransfer } from '../../../utils'
26+
27+
describe('Utils > encoding > encodeTransfer', () => {
28+
it('should encode an ERC-20 transfer correctly using the pre-defined token list', () => {
29+
const result = encodeTransfer(
30+
MockRecipientAddress,
31+
ContractAddress.PolygonAmoy_USDC,
32+
100n,
33+
)
34+
expect(result).toEqual(MockEncodedPredefinedTokenTransferResult)
35+
})
36+
37+
it('should encode an ERC-20 transfer correctly using the passed-in token address', () => {
38+
const result = encodeTransfer(
39+
MockRecipientAddress,
40+
'0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
41+
1000n,
42+
)
43+
expect(result).toEqual(MockEncodedERC20TransferResult)
44+
})
45+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at.
9+
*
10+
* Http://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
export enum ContractAddress {
20+
Arbitrum_USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
21+
Arbitrum_ARB = '0x912CE59144191C1204E64559FE8253a0e49E6548',
22+
ArbitrumSepolia_USDC = '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
23+
24+
// Polygon Tokens
25+
Polygon_USDC = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',
26+
PolygonAmoy_USDC = '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582',
27+
}

‎packages/w3s-web-core-sdk/src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19+
export * from './contractAddress'
1920
export * from './provider'
2021
export * from './smartAccount'

‎packages/w3s-web-core-sdk/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ export * from './actions'
2525
// Clients
2626
export * from './clients'
2727

28+
// Constants
29+
export { ContractAddress } from './constants'
30+
2831
// Providers
2932
export * from './providers'
3033

34+
// Utils
35+
export { encodeTransfer } from './utils'
36+
3137
// Types
3238
export {
3339
WebAuthnMode,

‎packages/w3s-web-core-sdk/src/types/modularWallets.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,17 @@ export interface ModularWallet {
120120
* The Get Circle modular wallet address response.
121121
*/
122122
export type GetAddressReturnType = ModularWallet
123+
124+
/**
125+
* The return type for encodeTransfer.
126+
*/
127+
export interface EncodeTransferReturnType {
128+
/**
129+
* The encoded data.
130+
*/
131+
data: Hex
132+
/**
133+
* The token address.
134+
*/
135+
to: Hex
136+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at.
9+
*
10+
* Http://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import { encodeFunctionData, erc20Abi } from 'viem'
20+
21+
import type { EncodeTransferReturnType } from '../../types'
22+
import type { ContractAddress } from 'src/constants'
23+
import type { Hex } from 'viem'
24+
25+
/**
26+
* Encode the ERC20 transfer for user operations.
27+
* @param to - The recipient address.
28+
* @param token - The token address you want to transfer.
29+
* @param amount - The amount to transfer.
30+
* @returns The encoded transfer.
31+
*/
32+
export function encodeTransfer(
33+
to: Hex,
34+
token: ContractAddress | Hex,
35+
amount: bigint,
36+
): EncodeTransferReturnType {
37+
const data = encodeFunctionData({
38+
abi: erc20Abi,
39+
functionName: 'transfer',
40+
args: [to, amount],
41+
})
42+
43+
return { data, to: token }
44+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at.
9+
*
10+
* Http://www.apache.org/licenses/LICENSE-2.0.
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
export * from './encodeTransfer'

‎packages/w3s-web-core-sdk/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
export * from './address'
20+
export * from './encoding'
2021
export * from './mock'
2122
export * from './publicKey'
2223
export * from './rpc'

0 commit comments

Comments
 (0)