Skip to content

Commit c41dc8b

Browse files
committed
Add network config code
1 parent 10e3eef commit c41dc8b

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

packages/core/zama/src/confidentialFungible.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function testConfidentialFungible(title: string, opts: Partial<ConfidentialFungi
1212
name: 'MyToken',
1313
symbol: 'MTK',
1414
tokenURI: '',
15+
networkConfig: 'zama-sepolia',
1516
...opts,
1617
});
1718
t.snapshot(printContract(c));
@@ -30,6 +31,7 @@ function testAPIEquivalence(title: string, opts?: ConfidentialFungibleOptions) {
3031
name: 'MyToken',
3132
symbol: 'MTK',
3233
tokenURI: '',
34+
networkConfig: 'zama-sepolia',
3335
...opts,
3436
}),
3537
),
@@ -57,6 +59,7 @@ function testPremint(scenario: string, premint: string, expectedError?: string)
5759
name: 'MyToken',
5860
symbol: 'MTK',
5961
tokenURI: '',
62+
networkConfig: 'zama-sepolia',
6063
premint,
6164
}),
6265
);
@@ -66,6 +69,7 @@ function testPremint(scenario: string, premint: string, expectedError?: string)
6669
name: 'MyToken',
6770
symbol: 'MTK',
6871
tokenURI: '',
72+
networkConfig: 'zama-sepolia',
6973
premint,
7074
});
7175
t.snapshot(printContract(c));
@@ -136,6 +140,7 @@ testAPIEquivalence('confidentialFungible API full upgradeable', {
136140
name: 'CustomToken',
137141
symbol: 'CTK',
138142
tokenURI: 'http://example.com',
143+
networkConfig: 'zama-ethereum',
139144
premint: '2000',
140145
access: 'roles',
141146
wrappable: true,

packages/core/zama/src/confidentialFungible.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import { clockModeDefault, setClockMode } from './set-clock-mode';
99
import { OptionsError } from './error';
1010
import { toUint256, UINT256_MAX } from './utils/convert-strings';
1111

12-
export const crossChainBridgingOptions = [false, 'custom', 'superchain'] as const;
13-
export type CrossChainBridging = (typeof crossChainBridgingOptions)[number];
12+
export const networkConfigOptions = ['zama-sepolia', 'zama-ethereum'] as const;
13+
export type NetworkConfig = (typeof networkConfigOptions)[number];
1414

1515
export interface ConfidentialFungibleOptions extends CommonOptions {
1616
name: string;
1717
symbol: string;
1818
tokenURI: string;
19+
networkConfig: NetworkConfig;
1920
premint?: string;
2021
wrappable?: boolean;
2122
/**
@@ -29,6 +30,7 @@ export const defaults: Required<ConfidentialFungibleOptions> = {
2930
name: 'MyToken',
3031
symbol: 'MTK',
3132
tokenURI: '',
33+
networkConfig: 'zama-sepolia',
3234
premint: '0',
3335
wrappable: false,
3436
votes: false,
@@ -59,6 +61,7 @@ export function buildConfidentialFungible(opts: ConfidentialFungibleOptions): Co
5961
const { info } = allOpts;
6062

6163
addBase(c, allOpts.name, allOpts.symbol, allOpts.tokenURI);
64+
addNetworkConfig(c, allOpts.networkConfig);
6265

6366
if (allOpts.premint) {
6467
addPremint(c, allOpts.premint);
@@ -98,6 +101,20 @@ function addBase(c: ContractBuilder, name: string, symbol: string, tokenURI: str
98101
c.addOverride(ConfidentialFungibleToken, functions.decimals);
99102
}
100103

104+
function addNetworkConfig(c: ContractBuilder, network: NetworkConfig) {
105+
if (network === 'zama-sepolia') {
106+
c.addParent({
107+
name: 'SepoliaConfig',
108+
path: '@fhevm/solidity/config/ZamaConfig.sol',
109+
});
110+
} else if (network === 'zama-ethereum') {
111+
c.addParent({
112+
name: 'EthereumConfig',
113+
path: '@fhevm/solidity/config/ZamaConfig.sol',
114+
});
115+
}
116+
}
117+
101118
export const premintPattern = /^(\d*)(?:\.(\d+))?(?:e(\d+))?$/;
102119

103120
function scaleByPowerOfTen(base: bigint, exponent: number): bigint {

packages/core/zama/src/get-imports.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { generateSources } from './generate/sources';
66
import { buildGeneric } from './build-generic';
77

88
test('confidential fungible basic', t => {
9-
const c = buildConfidentialFungible({ name: 'MyToken', symbol: 'MTK', tokenURI: '' });
9+
const c = buildConfidentialFungible({ name: 'MyToken', symbol: 'MTK', tokenURI: '', networkConfig: 'zama-sepolia' });
1010
const sources = getImports(c);
1111
const files = Object.keys(sources).sort();
1212

packages/ui/src/zama/ConfidentialFungibleControls.svelte

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@
4747
</label>
4848

4949
<div class="labeled-input">
50-
<span>Network</span>
50+
<span class="flex justify-between pr-2">
51+
Network Configuration
52+
<HelpTooltip>Adds configuration to use FHEVM contracts provided by Zama on the specified network.</HelpTooltip>
53+
</span>
5154
<div class="checkbox-group">
52-
<label class:checked={opts.network === 'sepolia'}>
53-
<input type="radio" bind:group={opts.network} value="sepolia" />
55+
<label class:checked={opts.networkConfig === 'zama-sepolia'}>
56+
<input type="radio" bind:group={opts.networkConfig} value="zama-sepolia" />
5457
Sepolia
5558
</label>
56-
<label class:checked={opts.network === 'ethereum'}>
57-
<input type="radio" bind:group={opts.network} value="ethereum" />
59+
<label class:checked={opts.networkConfig === 'zama-ethereum'}>
60+
<input type="radio" bind:group={opts.networkConfig} value="zama-ethereum" />
5861
Ethereum
5962
</label>
6063
</div>

0 commit comments

Comments
 (0)