Skip to content

Commit ecc4826

Browse files
ozgunozerkericglaubrozorec
authored
Stellar v0.2.0 (#531)
Co-authored-by: Eric Lau <[email protected]> Co-authored-by: Boyan Barakov <[email protected]>
1 parent 16c85e6 commit ecc4826

37 files changed

+2773
-199
lines changed

.changeset/silver-mammals-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openzeppelin/wizard-stellar': minor
3+
---
4+
5+
Add NonFungible extension and minor refactorings to Fungible (crate renamings, etc.).

.github/workflows/compile-cairo-alpha-project.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
paths:
66
- 'packages/core/cairo_alpha/**'
77
push:
8+
paths:
9+
- 'packages/core/cairo_alpha/**'
810

911
jobs:
1012
validate-cairo-alpha:
@@ -22,7 +24,7 @@ jobs:
2224
with:
2325
node-version: 20.x
2426
cache: 'yarn'
25-
27+
2628
- name: Install dependencies
2729
working-directory: packages/core/cairo_alpha
2830
run: yarn install --network-concurrency 1
@@ -32,7 +34,7 @@ jobs:
3234
run: |
3335
SCARB_VERSION=$(grep 'scarb-version = ' Scarb.toml | sed 's/scarb-version = "\(.*\)"/\1/')
3436
echo "SCARB_VERSION=$SCARB_VERSION" >> "$GITHUB_ENV"
35-
37+
3638
- name: Setup Scarb
3739
uses: software-mansion/setup-scarb@f6ad35129872f897bdea556c09e11af8fb3293c0 #v1.5.1
3840
with:
@@ -74,5 +76,5 @@ jobs:
7476
echo "✅ Compiled $proj_name!"
7577
echo "---------------------------------"
7678
fi
77-
79+
7880
done

.github/workflows/compile-cairo-project.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
paths:
66
- 'packages/core/cairo/**'
77
push:
8+
paths:
9+
- 'packages/core/cairo/**'
810

911
jobs:
1012
validate-cairo:
@@ -22,7 +24,7 @@ jobs:
2224
with:
2325
node-version: 20.x
2426
cache: 'yarn'
25-
27+
2628
- name: Install dependencies
2729
working-directory: packages/core/cairo
2830
run: yarn install --network-concurrency 1
@@ -32,7 +34,7 @@ jobs:
3234
run: |
3335
SCARB_VERSION=$(grep 'scarb-version = ' Scarb.toml | sed 's/scarb-version = "\(.*\)"/\1/')
3436
echo "SCARB_VERSION=$SCARB_VERSION" >> "$GITHUB_ENV"
35-
37+
3638
- name: Setup Scarb
3739
uses: software-mansion/setup-scarb@f6ad35129872f897bdea556c09e11af8fb3293c0 #v1.5.1
3840
with:
@@ -74,5 +76,5 @@ jobs:
7476
echo "✅ Compiled $proj_name!"
7577
echo "---------------------------------"
7678
fi
77-
79+
7880
done

packages/core/solidity/src/kind.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type Kind = GenericOptions['kind'];
44

55
export function sanitizeKind(kind: unknown): Kind {
66
if (typeof kind === 'string') {
7-
const sanitized = kind.replace(/^(ERC|.)/i, c => c.toUpperCase());
7+
const sanitized = kind.replace(/^(ERC|.)/i, c => c.toUpperCase()).replace(/^(RealWorldAsset)$/i, 'RealWorldAsset');
88
if (isKind(sanitized)) {
99
return sanitized;
1010
}

packages/core/stellar/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This package provides a programmatic API. For a web interface, see https://wizar
1212

1313
The following contract types are supported:
1414
- `fungible`
15+
- `nonFungible`
1516

1617
Each contract type has functions/constants as defined below.
1718

packages/core/stellar/src/add-pausable.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { requireAccessControl } from './set-access-control';
55
import { defineFunctions } from './utils/define-functions';
66

77
export function addPausable(c: ContractBuilder, access: Access) {
8-
c.addUseClause('openzeppelin_pausable', 'self', { alias: 'pausable' });
9-
c.addUseClause('openzeppelin_pausable', 'Pausable');
8+
c.addUseClause('stellar_pausable', 'self', { alias: 'pausable' });
9+
c.addUseClause('stellar_pausable', 'Pausable');
1010

1111
const pausableTrait = {
12-
name: 'Pausable',
13-
for: c.name,
12+
traitName: 'Pausable',
13+
structName: c.name,
1414
tags: ['contractimpl'],
1515
section: 'Utils',
1616
};
1717

18-
c.addFunction(pausableTrait, functions.paused);
19-
c.addFunction(pausableTrait, functions.pause);
20-
c.addFunction(pausableTrait, functions.unpause);
18+
c.addTraitFunction(pausableTrait, functions.paused);
19+
c.addTraitFunction(pausableTrait, functions.pause);
20+
c.addTraitFunction(pausableTrait, functions.unpause);
2121

2222
requireAccessControl(c, pausableTrait, functions.pause, access, 'caller');
2323
requireAccessControl(c, pausableTrait, functions.unpause, access, 'caller');
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { getSelfArg } from './common-options';
2+
import type { Access } from './set-access-control';
3+
import { requireAccessControl } from './set-access-control';
4+
import type { ContractBuilder } from './contract';
5+
import { defineFunctions } from './utils/define-functions';
6+
7+
export function addUpgradeable(c: ContractBuilder, access: Access) {
8+
const functions = defineFunctions({
9+
_require_auth: {
10+
args: [getSelfArg(), { name: 'operator', type: '&Address' }],
11+
code: ['operator.require_auth();'],
12+
},
13+
});
14+
15+
c.addUseClause('stellar_upgradeable', 'UpgradeableInternal');
16+
c.addUseClause('stellar_upgradeable_macros', 'Upgradeable');
17+
18+
c.addDerives('Upgradeable');
19+
20+
const upgradeableTrait = {
21+
traitName: 'UpgradeableInternal',
22+
structName: c.name,
23+
tags: [],
24+
section: 'Utils',
25+
};
26+
27+
c.addTraitFunction(upgradeableTrait, functions._require_auth);
28+
29+
requireAccessControl(c, upgradeableTrait, functions._require_auth, access, '*operator');
30+
}

packages/core/stellar/src/api.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { CommonContractOptions } from './common-options';
22
import type { FungibleOptions } from './fungible';
3+
import type { NonFungibleOptions } from './non-fungible';
34
import { printFungible, defaults as fungibledefaults } from './fungible';
5+
import { printNonFungible, defaults as nonFungibledefaults } from './non-fungible';
46

57
export interface WizardContractAPI<Options extends CommonContractOptions> {
68
/**
@@ -23,8 +25,14 @@ export interface AccessControlAPI<Options extends CommonContractOptions> {
2325
}
2426

2527
export type Fungible = WizardContractAPI<FungibleOptions>; // TODO add AccessControlAPI<FungibleOptions> when access control is implemented, if useful
28+
export type NonFungible = WizardContractAPI<NonFungibleOptions>;
2629

2730
export const fungible: Fungible = {
2831
print: printFungible,
2932
defaults: fungibledefaults,
3033
};
34+
35+
export const nonFungible: NonFungible = {
36+
print: printNonFungible,
37+
defaults: nonFungibledefaults,
38+
};
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import type { FungibleOptions } from './fungible';
22
import { buildFungible } from './fungible';
3+
import type { NonFungibleOptions } from './non-fungible';
4+
import { buildNonFungible } from './non-fungible';
35

46
export interface KindedOptions {
57
Fungible: { kind: 'Fungible' } & FungibleOptions;
8+
NonFungible: { kind: 'NonFungible' } & NonFungibleOptions;
69
}
710

811
export type GenericOptions = KindedOptions[keyof KindedOptions];
@@ -11,9 +14,13 @@ export function buildGeneric(opts: GenericOptions) {
1114
switch (opts.kind) {
1215
case 'Fungible':
1316
return buildFungible(opts);
17+
18+
case 'NonFungible':
19+
return buildNonFungible(opts);
20+
1421
default: {
15-
const _: never = opts.kind; // TODO: When there are additional kinds above, change this assignment to just `opts` instead of `opts.kind`
16-
throw new Error('Unknown ERC');
22+
const _: never = opts;
23+
throw new Error('Unknown kind');
1724
}
1825
}
1926
}

packages/core/stellar/src/contract.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22

3-
import type { BaseFunction, BaseImplementedTrait } from './contract';
3+
import type { BaseFunction, BaseTraitImplBlock } from './contract';
44
import { ContractBuilder } from './contract';
55
import { printContract } from './print';
66

@@ -23,39 +23,41 @@ test('contract with constructor code with semicolon', t => {
2323

2424
test('contract with function code before', t => {
2525
const Foo = new ContractBuilder('Foo');
26-
const trait: BaseImplementedTrait = {
27-
name: 'External',
28-
for: 'ExternalTrait',
26+
const trait: BaseTraitImplBlock = {
27+
traitName: 'External',
28+
structName: 'ExternalTrait',
2929
tags: ['othertag', 'contractimpl'],
3030
};
31-
Foo.addImplementedTrait(trait);
31+
Foo.addTraitImplBlock(trait);
3232
const fn: BaseFunction = {
33+
pub: false,
3334
name: 'someFunction',
3435
args: [],
3536
code: ['someFunction()'],
3637
};
37-
Foo.addFunction(trait, fn);
38-
Foo.addFunctionTag(trait, fn, 'functiontag');
39-
Foo.addFunctionCodeBefore(trait, fn, ['before()']);
38+
Foo.addTraitFunction(trait, fn);
39+
Foo.addFunctionTag(fn, 'functiontag', trait);
40+
Foo.addFunctionCodeBefore(fn, ['before()'], trait);
4041
t.snapshot(printContract(Foo));
4142
});
4243

4344
test('contract with function code before with semicolons', t => {
4445
const Foo = new ContractBuilder('Foo');
45-
const trait: BaseImplementedTrait = {
46-
name: 'External',
47-
for: 'ExternalTrait',
46+
const trait: BaseTraitImplBlock = {
47+
traitName: 'External',
48+
structName: 'ExternalTrait',
4849
tags: ['othertag', 'contractimpl'],
4950
};
50-
Foo.addImplementedTrait(trait);
51+
Foo.addTraitImplBlock(trait);
5152
const fn: BaseFunction = {
53+
pub: false,
5254
name: 'someFunction',
5355
args: [],
5456
code: ['someFunction();'],
5557
};
56-
Foo.addFunction(trait, fn);
57-
Foo.addFunctionTag(trait, fn, 'functiontag');
58-
Foo.addFunctionCodeBefore(trait, fn, ['before();']);
58+
Foo.addTraitFunction(trait, fn);
59+
Foo.addFunctionTag(fn, 'functiontag', trait);
60+
Foo.addFunctionCodeBefore(fn, ['before();'], trait);
5961
t.snapshot(printContract(Foo));
6062
});
6163

0 commit comments

Comments
 (0)