Skip to content

Commit 0bd7843

Browse files
committed
Implement wrappable
1 parent 8d5d72b commit 0bd7843

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

packages/core/zama/src/confidentialFungible.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export function buildConfidentialFungible(opts: ConfidentialFungibleOptions): Co
6464
addPremint(c, allOpts.premint);
6565
}
6666

67-
// if (allOpts.mintable) {
68-
// addMintable(c);
69-
// }
67+
if (allOpts.mintable) {
68+
addWrappable(c);
69+
}
7070

7171
if (allOpts.votes) {
7272
const clockMode = allOpts.votes === true ? clockModeDefault : allOpts.votes;
@@ -95,6 +95,7 @@ function addBase(c: ContractBuilder, name: string, symbol: string, tokenURI: str
9595
});
9696
c.addOverride(ConfidentialFungibleToken, functions._update);
9797
c.addOverride(ConfidentialFungibleToken, functions.confidentialTotalSupply);
98+
c.addOverride(ConfidentialFungibleToken, functions.decimals);
9899
}
99100

100101
export const premintPattern = /^(\d*)(?:\.(\d+))?(?:e(\d+))?$/;
@@ -159,9 +160,25 @@ function checkPotentialPremintOverflow(baseUnits: bigint, decimalPlace: number)
159160
}
160161
}
161162

162-
// function addMintable(c: ContractBuilder) { // TODO change to wrappable
163-
// c.addFunctionCode('_mint(to, amount);', functions.mint);
164-
// }
163+
function addWrappable(c: ContractBuilder) {
164+
const underlyingArg = 'underlying';
165+
166+
c.addImportOnly({
167+
name: 'IERC20',
168+
path: '@openzeppelin/contracts/interfaces/IERC20.sol',
169+
});
170+
c.addConstructorArgument({
171+
type: 'IERC20',
172+
name: underlyingArg,
173+
});
174+
175+
const ConfidentialFungibleTokenERC20Wrapper = {
176+
name: 'ConfidentialFungibleTokenERC20Wrapper',
177+
path: '@openzeppelin/confidential-contracts/token/extensions/ConfidentialFungibleTokenERC20Wrapper.sol',
178+
};
179+
c.addParent(ConfidentialFungibleTokenERC20Wrapper, [{ lit: underlyingArg }]);
180+
c.addOverride(ConfidentialFungibleTokenERC20Wrapper, functions.decimals);
181+
}
165182

166183
function addVotes(c: ContractBuilder, name: string, clockMode: ClockMode) {
167184
const EIP712 = {
@@ -207,5 +224,11 @@ export const functions = defineFunctions({
207224
args: [
208225
{ name: 'handle', type: 'bytes32' },
209226
],
210-
}
227+
},
228+
decimals: {
229+
kind: 'public' as const,
230+
mutability: 'view',
231+
args: [],
232+
returns: ['uint8'],
233+
},
211234
});

0 commit comments

Comments
 (0)