Skip to content

Commit 2ec1351

Browse files
author
ci-bot
committed
add cicles template
1 parent e273e83 commit 2ec1351

File tree

12 files changed

+314
-0
lines changed

12 files changed

+314
-0
lines changed

apps/remix-ide/src/app/plugins/templates-selection/templates.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ export const templates = (intl: any, plugin: any): TemplateGroup[] => {
406406
},
407407
],
408408
},
409+
{
410+
name: "About Circles",
411+
items: [
412+
{ value: "circles", tagList: [], displayName: 'About Circles', description: 'Templates for interacting with the Cicles Sdk' }
413+
]
414+
},
409415
{
410416
name: 'GitHub Actions',
411417
items: [

libs/remix-ui/workspace/src/lib/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const TEMPLATE_NAMES = {
2020
'uniswapV4HookBookMultiSigSwapHook': 'Uniswap V4 HookBook MultiSigSwapHook',
2121
'accountAbstraction': 'Account Abstraction Template',
2222
'introToEIP7702': 'Intro to EIP-7702',
23+
'circles': 'About Circles'
2324
}
2425

2526
export const TEMPLATE_METADATA: Record<string, TemplateType> = {

libs/remix-ws-templates/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export { default as hashchecker } from './templates/hashchecker'
1313
export { default as rln } from './templates/rln'
1414
export { default as multNr } from './templates/multiplierNoir'
1515
export { default as stealthDropNr } from './templates/stealthdropNoir'
16+
export { default as circles } from './templates/circles'
1617

1718
export { contractDeployerScripts } from './script-templates/contract-deployer'
1819
export { etherscanScripts } from './script-templates/etherscan'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": "*.sol",
5+
"options": {
6+
"printWidth": 80,
7+
"tabWidth": 4,
8+
"useTabs": false,
9+
"singleQuote": false,
10+
"bracketSpacing": false
11+
}
12+
},
13+
{
14+
"files": "*.yml",
15+
"options": {
16+
}
17+
},
18+
{
19+
"files": "*.yaml",
20+
"options": {
21+
}
22+
},
23+
{
24+
"files": "*.toml",
25+
"options": {
26+
}
27+
},
28+
{
29+
"files": "*.json",
30+
"options": {
31+
}
32+
},
33+
{
34+
"files": "*.js",
35+
"options": {
36+
}
37+
},
38+
{
39+
"files": "*.ts",
40+
"options": {
41+
}
42+
}
43+
]
44+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
### Circles
3+
4+
This template introduces the usage of the Circles sdk.
5+
6+
## create-group.ts
7+
8+
This script creates a new group on the Circles platform using the Circles SDK. It initializes the SDK with a BrowserProviderContractRunner,
9+
defines the group profile, sets up the base group options, creates the group profile CID, creates the base group,
10+
waits for transaction confirmation, extracts the group address from the transaction receipt, and retrieves the group's avatar.
11+
12+
## group-creation-tx.ts
13+
14+
This script retrieves and logs information about a group created on the Circles platform using the Circles SDK.
15+
It initializes the SDK with a BrowserProviderContractRunner, fetches a transaction receipt,
16+
extracts the group address from the transaction logs, and then retrieves and logs the group's avatar
17+
and its trust relations.
18+
19+
## invite-to-group.ts
20+
21+
This script invites a user to a group on the Circles platform using the Circles SDK. It initializes the SDK with a BrowserProviderContractRunner,
22+
fetches a transaction receipt, extracts the group address from the transaction logs, retrieves the group's avatar,
23+
and then checks if the user is already trusted by the group and trusts the user.
24+
25+
## pathfinder.ts
26+
27+
This script finds a path between two addresses on the Circles platform using the CirclesRpc. It initializes the CirclesRpc with the provided URL,
28+
and then calls the 'circlesV2_findPath' method with the source address, target address, and value.
29+
30+
## set-owner.ts
31+
32+
This script sets the owner of a group on the Circles platform using the Circles SDK. It initializes the SDK with a BrowserProviderContractRunner,
33+
fetches a transaction receipt, extracts the group address from the transaction logs, retrieves the group's avatar,
34+
and then sets the owner of the group.
35+
36+
## user.ts
37+
38+
This script retrieves and logs information about a user's avatar on the Circles platform using the Circles SDK.
39+
It initializes the SDK with a BrowserProviderContractRunner, retrieves the avatar information,
40+
and then logs the mintable amount and the avatar information.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default async () => {
2+
return {
3+
// @ts-ignore
4+
'scripts/group-creation-tx.ts': (await import('!!raw-loader!./scripts/group-creation-tx.ts')).default,
5+
// @ts-ignore
6+
'scripts/create-group.ts': (await import('!!raw-loader!./scripts/create-group.ts')).default,
7+
// @ts-ignore
8+
'scripts/invite-to-group.ts': (await import('!!raw-loader!./scripts/invite-to-group.ts')).default,
9+
// @ts-ignore
10+
'scripts/pathfinder.ts': (await import('!!raw-loader!./scripts/pathfinder.ts')).default,
11+
// @ts-ignore
12+
'scripts/set-owner.ts': (await import('!!raw-loader!./scripts/set-owner.ts')).default,
13+
// @ts-ignore
14+
'scripts/user.ts': (await import('!!raw-loader!./scripts/user.ts')).default,
15+
// @ts-ignore
16+
'.prettierrc.json': (await import('raw-loader!./.prettierrc')).default,
17+
// @ts-ignore
18+
'README.md': (await import('raw-loader!./README.md')).default
19+
}
20+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Sdk } from '@circles-sdk/sdk'
2+
import { BrowserProviderContractRunner } from "@circles-sdk/adapter-ethers"
3+
import { cidV0ToUint8Array } from '@circles-sdk/utils'
4+
import { ethers } from 'ethers'
5+
6+
(window as any).ethereum = web3Provider
7+
8+
const run = async () => {
9+
// Initialize the SDK
10+
const adapter = new BrowserProviderContractRunner();
11+
await adapter.init();
12+
const sdk = new Sdk(adapter)
13+
const sender = await (new ethers.BrowserProvider(web3Provider)).getSigner()
14+
15+
// Define the group profile (symbol is required)
16+
const groupProfile = {
17+
name: '',
18+
symbol: '',
19+
description: '',
20+
imageUrl: '', // optional, can be uploaded via SDK
21+
previewImageUrl: '', // optional, used for previews
22+
}
23+
24+
// Define base group setup options
25+
const circlesGroupOwner = ''
26+
const groupOwner = circlesGroupOwner
27+
const serviceAddress = sender.address // Replace with actual service address
28+
const feeCollection = circlesGroupOwner // Replace with actual treasury address
29+
const initialConditions = []
30+
31+
// Step 1: Create the group profile (CID will be returned)
32+
const profileCID = await sdk.profiles.create(groupProfile)
33+
if (!profileCID) throw new Error('Failed to create profile CID')
34+
35+
// Step 2: Create the base group using the factory
36+
console.log('group owner will be', sender)
37+
const tx = await sdk.baseGroupFactory.createBaseGroup(
38+
groupOwner, // Usually wallet address of the sender
39+
serviceAddress,
40+
feeCollection,
41+
initialConditions,
42+
groupProfile.name,
43+
groupProfile.symbol,
44+
cidV0ToUint8Array(profileCID), // Convert CID to bytes
45+
)
46+
47+
// Wait for transaction confirmation
48+
const receipt = await tx.wait()
49+
50+
console.log('receipt', receipt)
51+
52+
// Step 3: Extract the group address from emitted events
53+
const groupAddress = ethers.stripZerosLeft(receipt.logs[15].topics[1])
54+
55+
// Step 4: Get the avatar for the created group
56+
const baseGroupAvatar = await sdk.getAvatar(groupAddress.toLowerCase())
57+
58+
console.log('Base group created at:', groupAddress)
59+
console.log('Group avatar:', baseGroupAvatar)
60+
}
61+
62+
run().catch(console.error).then(console.log)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ethers } from 'ethers'
2+
import { Sdk } from '@circles-sdk/sdk'
3+
import { BrowserProviderContractRunner } from "@circles-sdk/adapter-ethers"
4+
5+
const run = async () => {
6+
// Initialize the SDK
7+
const adapter = new BrowserProviderContractRunner();
8+
await adapter.init();
9+
const sdk = new Sdk(adapter)
10+
11+
const txHash = '' // transaction which registered the group.
12+
13+
const provider = new ethers.BrowserProvider(web3Provider)
14+
const receipt = await provider.getTransactionReceipt(txHash)
15+
const groupAddress = ethers.stripZerosLeft(receipt.logs[15].topics[1])
16+
17+
console.log('group address', groupAddress)
18+
const baseGroupAvatar = await sdk.getAvatar(groupAddress.toLowerCase())
19+
20+
console.log('group avatar', baseGroupAvatar)
21+
console.log('owner is', await baseGroupAvatar.owner())
22+
console.log('trust relations are', await baseGroupAvatar.getTrustRelations())
23+
}
24+
25+
run().then(console.log).catch(console.error)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ethers } from 'ethers'
2+
import { Sdk } from '@circles-sdk/sdk'
3+
import { BrowserProviderContractRunner } from "@circles-sdk/adapter-ethers"
4+
5+
(window as any).ethereum = web3Provider
6+
7+
const run = async () => {
8+
// Initialize the SDK
9+
const adapter = new BrowserProviderContractRunner();
10+
await adapter.init();
11+
const sdk = new Sdk(adapter)
12+
13+
const user = ''
14+
const txHash = '' // transaction which registered the group.
15+
16+
const provider = new ethers.BrowserProvider(web3Provider)
17+
const receipt = await provider.getTransactionReceipt(txHash)
18+
const groupAddress = ethers.stripZerosLeft(receipt.logs[15].topics[1])
19+
20+
console.log('group address', groupAddress)
21+
const baseGroupAvatar = await sdk.getAvatar(groupAddress.toLowerCase())
22+
23+
console.log('group avatar', baseGroupAvatar)
24+
25+
console.log('owner', await baseGroupAvatar.owner())
26+
console.log('service', await baseGroupAvatar.service())
27+
28+
console.log(await baseGroupAvatar.isTrustedBy(user))
29+
30+
console.log(await baseGroupAvatar.trust(user))
31+
}
32+
33+
run().then(console.log).catch(console.error)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { CirclesRpc } from '@circles-sdk/data';
2+
3+
(window as any).ethereum = web3Provider
4+
5+
const chainConfig = {
6+
pathfinderUrl: 'https://pathfinder.aboutcircles.com',
7+
circlesRpcUrl: 'https://rpc.aboutcircles.com',
8+
v1HubAddress: '0xdbf22d4e8962db3b2f1d9ff55be728a887e47710',
9+
v2HubAddress: '0x2066CDA98F98397185483aaB26A89445addD6740',
10+
migrationAddress: '0x2A545B54bb456A0189EbC53ed7090BfFc4a6Af94'
11+
};
12+
13+
const sourceAddress = ''
14+
const targetAddress = ''
15+
const value = '1000000000000000000'
16+
/*
17+
{"jsonrpc":"2.0","id":0,"method":"circlesV2_findPath","params":[{"Source":"0xf7f307601497eAD8217543Fc9B350Ae6DA5fB5eF","Sink":"0x3765c1633eA9dDaD819B1b7d9A27B1E117f789a2","TargetFlow":"1000000000000000000"}]}
18+
*/
19+
const run = async () => {
20+
try {
21+
const res = await new CirclesRpc(chainConfig.circlesRpcUrl).call<any>('circlesV2_findPath', [{
22+
Source: sourceAddress,
23+
Sink: targetAddress,
24+
TargetFlow: value
25+
}])
26+
console.log(res.result)
27+
} catch (e) {
28+
console.error(e)
29+
}
30+
}
31+
32+
run().catch(console.error).then(console.log)

0 commit comments

Comments
 (0)