Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/w3s-web-core-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@circle-fin/modular-wallets-core",
"description": "Serverless Typescript SDK",
"version": "1.0.3",
"version": "1.0.4",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/w3s-web-core-sdk/src/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
export * from './accounts'
export * from './clients'
export * from './providers'
export * from './utils'
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at.
*
* Http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { Hex } from 'viem'

/**
* Mocks for the utility function - encodeTransfer to address parameter.
*/
export const MockRecipientAddress: Hex =
'0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'

/**
* Mocks for the utility function - encodeTransfer response.
*/
export const MockEncodedPredefinedTokenTransferResult = {
data: '0xa9059cbb000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000000000000000064',
to: '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582',
}

/**
* Mocks for the utility function - encodeTransfer response.
*/
export const MockEncodedERC20TransferResult = {
data: '0xa9059cbb000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e8',
to: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
}
19 changes: 19 additions & 0 deletions packages/w3s-web-core-sdk/src/__mocks__/utils/encoding/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at.
*
* Http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './encodeTransfer.Mock'
19 changes: 19 additions & 0 deletions packages/w3s-web-core-sdk/src/__mocks__/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at.
*
* Http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './encoding'
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at.
*
* Http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
MockEncodedERC20TransferResult,
MockEncodedPredefinedTokenTransferResult,
MockRecipientAddress,
} from '../../../__mocks__'
import { ContractAddress } from '../../../constants'
import { encodeTransfer } from '../../../utils'

describe('Utils > encoding > encodeTransfer', () => {
it('should encode an ERC-20 transfer correctly using the pre-defined token list', () => {
const result = encodeTransfer(
MockRecipientAddress,
ContractAddress.PolygonAmoy_USDC,
100n,
)
expect(result).toEqual(MockEncodedPredefinedTokenTransferResult)
})

it('should encode an ERC-20 transfer correctly using the passed-in token address', () => {
const result = encodeTransfer(
MockRecipientAddress,
'0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
1000n,
)
expect(result).toEqual(MockEncodedERC20TransferResult)
})
})
27 changes: 27 additions & 0 deletions packages/w3s-web-core-sdk/src/constants/contractAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at.
*
* Http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export enum ContractAddress {
Arbitrum_USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
Arbitrum_ARB = '0x912CE59144191C1204E64559FE8253a0e49E6548',
ArbitrumSepolia_USDC = '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',

// Polygon Tokens
Polygon_USDC = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',
PolygonAmoy_USDC = '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582',
}
1 change: 1 addition & 0 deletions packages/w3s-web-core-sdk/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
* limitations under the License.
*/

export * from './contractAddress'
export * from './provider'
export * from './smartAccount'
6 changes: 6 additions & 0 deletions packages/w3s-web-core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ export * from './actions'
// Clients
export * from './clients'

// Constants
export { ContractAddress } from './constants'

// Providers
export * from './providers'

// Utils
export { encodeTransfer } from './utils'

// Types
export {
WebAuthnMode,
Expand Down
14 changes: 14 additions & 0 deletions packages/w3s-web-core-sdk/src/types/modularWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,17 @@ export interface ModularWallet {
* The Get Circle modular wallet address response.
*/
export type GetAddressReturnType = ModularWallet

/**
* The return type for encodeTransfer.
*/
export interface EncodeTransferReturnType {
/**
* The encoded data.
*/
data: Hex
/**
* The token address.
*/
to: Hex
}
44 changes: 44 additions & 0 deletions packages/w3s-web-core-sdk/src/utils/encoding/encodeTransfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at.
*
* Http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { encodeFunctionData, erc20Abi } from 'viem'

import type { EncodeTransferReturnType } from '../../types'
import type { ContractAddress } from 'src/constants'
import type { Hex } from 'viem'

/**
* Encode the ERC20 transfer for user operations.
* @param to - The recipient address.
* @param token - The token address you want to transfer.
* @param amount - The amount to transfer.
* @returns The encoded transfer.
*/
export function encodeTransfer(
to: Hex,
token: ContractAddress | Hex,
amount: bigint,
): EncodeTransferReturnType {
const data = encodeFunctionData({
abi: erc20Abi,
functionName: 'transfer',
args: [to, amount],
})

return { data, to: token }
}
19 changes: 19 additions & 0 deletions packages/w3s-web-core-sdk/src/utils/encoding/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at.
*
* Http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './encodeTransfer'
1 change: 1 addition & 0 deletions packages/w3s-web-core-sdk/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

export * from './address'
export * from './encoding'
export * from './mock'
export * from './publicKey'
export * from './rpc'
Expand Down