Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
31 changes: 19 additions & 12 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ Run tests with output:
cargo test -- --nocapture
```


### Prerequisites

- Rust toolchain (1.74.0+)
Expand Down Expand Up @@ -92,19 +91,25 @@ make deploy-testnet # Deploy contract to Soroban testnet
#### Example Workflow

1. Build and optimize contract:
```bash
make build
make optimize
```

```bash
make build
make optimize
```

2. Setup local sandbox (optional):
```bash
bash scripts/setup-local.sh
```

```bash
bash scripts/setup-local.sh
```

3. Deploy to testnet:
```bash
make deploy-testnet
```
- Contract ID will be written to `contract-deployment.json`.

```bash
make deploy-testnet
```

- Contract ID will be written to `contract-deployment.json`.

#### Environment Variables

Expand All @@ -113,11 +118,13 @@ make deploy-testnet # Deploy contract to Soroban testnet
#### Manual Steps (for reference)

You can still use Soroban CLI directly for custom deployments:

```bash
soroban contract build
soroban contract optimize --wasm target/wasm32-unknown-unknown/release/ancore_account.wasm
soroban contract deploy --wasm target/wasm32-unknown-unknown/release/ancore_account.optimized.wasm --source <deployer> --network testnet
```

- Ed25519 validation (native Stellar)
- Multi-signature
- WebAuthn support
Expand Down
6 changes: 5 additions & 1 deletion contracts/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ impl AncoreAccount {
}


if current_nonce != expected_nonce {
return Err(ContractError::InvalidNonce);
}

// Increment nonce
env.storage().instance().set(&DataKey::Nonce, &(current_nonce + 1));

Expand Down Expand Up @@ -439,7 +443,7 @@ mod test {
}

#[test]
#[should_panic(expected = "Invalid nonce")]
#[should_panic(expected = "Error(Contract, #4)")]
fn test_execute_rejects_invalid_nonce() {
let env = Env::default();
let contract_id = env.register_contract(None, AncoreAccount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"address": 2,
"nonce": 0
},
"auth": [
[],
[]
],
"auth": [[], []],
"ledger": {
"protocol_version": 21,
"sequence_number": 0,
Expand Down Expand Up @@ -306,4 +303,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"address": 3,
"nonce": 0
},
"auth": [
[],
[]
],
"auth": [[], []],
"ledger": {
"protocol_version": 21,
"sequence_number": 0,
Expand Down Expand Up @@ -213,27 +210,16 @@
"v0": {
"topics": [
{
"symbol": "log"
"symbol": "fn_return"
},
{
"symbol": "execute"
}
],
"data": {
"vec": [
{
"string": "caught panic 'Invalid nonce' from contract function 'Symbol(execute)'"
},
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
},
{
"symbol": "transfer"
},
{
"vec": []
},
{
"u64": 1
}
]
"error": {
"contract": 4
}
}
}
}
Expand All @@ -253,12 +239,12 @@
},
{
"error": {
"wasm_vm": "invalid_action"
"contract": 4
}
}
],
"data": {
"string": "caught error from function"
"string": "escalating Ok(ScErrorType::Contract) frame-exit to Err"
}
}
}
Expand All @@ -278,7 +264,7 @@
},
{
"error": {
"wasm_vm": "invalid_action"
"contract": 4
}
}
],
Expand Down Expand Up @@ -326,7 +312,7 @@
},
{
"error": {
"wasm_vm": "invalid_action"
"contract": 4
}
}
],
Expand All @@ -339,4 +325,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,4 @@
"failed_call": false
}
]
}
}
8 changes: 2 additions & 6 deletions contracts/account/test_snapshots/test/test_initialize.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"address": 2,
"nonce": 0
},
"auth": [
[],
[],
[]
],
"auth": [[], [], []],
"ledger": {
"protocol_version": 21,
"sequence_number": 0,
Expand Down Expand Up @@ -261,4 +257,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"address": 2,
"nonce": 0
},
"auth": [
[]
],
"auth": [[]],
"ledger": {
"protocol_version": 21,
"sequence_number": 0,
Expand Down Expand Up @@ -165,4 +163,4 @@
"failed_call": false
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,4 @@
"failed_call": false
}
]
}
}
6 changes: 3 additions & 3 deletions docs/PULL_REQUEST_WORKFLOW.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ git branch -d feat/your-feature-name # optional: delete local branch

## Branch naming

- `feat/thing` — new feature
- `fix/thing` — bugfix
- `chore/thing` — config, deps, tooling
- `feat/thing` — new feature
- `fix/thing` — bugfix
- `chore/thing` — config, deps, tooling

Example: `feat/contract-execute-nonce`, `fix/account-abstraction-types`.
16 changes: 16 additions & 0 deletions packages/account-abstraction/eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module.exports = [
ecmaVersion: 2020,
sourceType: 'module',
},
globals: {
Buffer: 'readonly',
TextEncoder: 'readonly',
},
},
plugins: {
'@typescript-eslint': tseslint,
Expand All @@ -21,4 +25,16 @@ module.exports = [
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
},
{
files: ['src/__tests__/**/*.ts'],
languageOptions: {
globals: {
describe: 'readonly',
beforeEach: 'readonly',
it: 'readonly',
expect: 'readonly',
jest: 'readonly',
},
},
},
];
10 changes: 5 additions & 5 deletions packages/account-abstraction/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --tsconfig tsconfig.json",
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
"test": "jest",
"lint": "eslint src/",
"clean": "rm -rf dist"
"build": "tsup src/index.ts --format cjs,esm --dts --tsconfig tsconfig.json",
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
"test": "jest",
"lint": "eslint src/",
"clean": "rm -rf dist"
},
"keywords": [
"ancore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ describe('AccountContract', () => {
it('returns method and to, function, args, expectedNonce', () => {
const to = 'CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC';
const fn = 'transfer';
const args: xdr.ScVal[] = [
new Address(OWNER_ADDRESS).toScVal(),
xdr.ScVal.scvU32(100),
];
const args: xdr.ScVal[] = [new Address(OWNER_ADDRESS).toScVal(), xdr.ScVal.scvU32(100)];
const inv = contract.execute(to, fn, args, 0);
expect(inv.method).toBe('execute');
expect(inv.args).toHaveLength(4);
Expand Down Expand Up @@ -215,9 +212,7 @@ describe('XDR encoding helpers', () => {
});

it('throws for wrong byte length', () => {
expect(() =>
publicKeyToBytes32ScVal(new Uint8Array(16))
).toThrow(TypeError);
expect(() => publicKeyToBytes32ScVal(new Uint8Array(16))).toThrow(TypeError);
});
});

Expand Down
Loading
Loading