Skip to content

Commit

Permalink
update for sdk 1.1.0 - host based 128 bit arithmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Sep 16, 2024
1 parent 5159c44 commit 8fbba4d
Show file tree
Hide file tree
Showing 56 changed files with 135 additions and 132 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [Stellar Soroban Examples for AssemblyScript](https://github.com/Soneso/as-soroban-examples)

![v1.0.1](https://img.shields.io/badge/v1.0.1-green.svg)
![v1.1.0](https://img.shields.io/badge/v1.1.0-green.svg)

AssemblyScript contract examples for [Soroban](https://soroban.stellar.org).

Expand Down
2 changes: 1 addition & 1 deletion add/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ The concrete types must also be defined in the [contract spec](https://github.co
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
2 changes: 1 addition & 1 deletion add/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"key" : "version",
"value" : "1.0.1"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions add/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "add",
"version": "1.0.0",
"version": "1.1.0",
"description": "as soroban contract example adding two integers",
"scripts": {
"asbuild:debug": "asc assembly/index.ts --target debug",
Expand All @@ -25,6 +25,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion atomic-swap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function move_token(token: AddressObject, from: AddressObject, to:AddressObject,
let t3Args = new Vec();
t3Args.pushBack(contract_address);
t3Args.pushBack(from);
t3Args.pushBack(i128sub(max_spend_amount,transfer_amount));
t3Args.pushBack(i128Sub(max_spend_amount,transfer_amount));
env.call(token, func, t3Args.getHostObject());
}
```
Expand Down
8 changes: 4 additions & 4 deletions atomic-swap/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as address from "as-soroban-sdk/lib/address";
import * as env from "as-soroban-sdk/lib/env";
import {AddressObject, I128Val, fromVoid, VoidVal, fromSmallSymbolStr} from "as-soroban-sdk/lib/value";
import { Vec } from "as-soroban-sdk/lib/vec";
import { i128lt, i128sub } from "as-soroban-sdk/lib/val128";
import { i128IsLowerThan, i128Sub } from "as-soroban-sdk/lib/arithm128";

enum SWAP_ERR_CODES {
NOT_ENOUGH_TOKEN_B_FOR_TOKEN_A = 1,
Expand Down Expand Up @@ -33,11 +33,11 @@ export function swap(a: AddressObject, b: AddressObject,


// Verify preconditions on the minimum price for both parties.
if (i128lt(amount_b, min_b_for_a)) { // amount_b < min_b_for_a
if (i128IsLowerThan(amount_b, min_b_for_a)) { // amount_b < min_b_for_a
context.failWithErrorCode(SWAP_ERR_CODES.NOT_ENOUGH_TOKEN_B_FOR_TOKEN_A);
}

if (i128lt(amount_a, min_a_for_b)) { // amount_a < min_a_for_b
if (i128IsLowerThan(amount_a, min_a_for_b)) { // amount_a < min_a_for_b
context.failWithErrorCode(SWAP_ERR_CODES.NOT_ENOUGH_TOKEN_B_FOR_TOKEN_A);
}

Expand Down Expand Up @@ -99,6 +99,6 @@ function move_token(token: AddressObject, from: AddressObject, to:AddressObject,
let t3Args = new Vec();
t3Args.pushBack(contract_address);
t3Args.pushBack(from);
t3Args.pushBack(i128sub(max_spend_amount,transfer_amount));
t3Args.pushBack(i128Sub(max_spend_amount,transfer_amount));
env.call(token, func, t3Args.getHostObject());
}
2 changes: 1 addition & 1 deletion atomic-swap/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions atomic-swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atomic_swap",
"version": "1.0.0",
"version": "1.1.0",
"description": "atomic swap contract example",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,6 +28,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion auth/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth",
"version": "1.0.0",
"version": "1.1.0",
"description": "demonstrates how to implement authentication and authorization using the Soroban Host-managed auth framework",
"main": "index.js",
"scripts": {
Expand All @@ -23,6 +23,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion contract_events/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions contract_events/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contract_events",
"version": "1.0.0",
"version": "1.1.0",
"description": "soroban contract example that publishes events",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,6 +28,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion cross_contract/contract_a/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions cross_contract/contract_a/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contract_a",
"version": "1.0.0",
"version": "1.1.0",
"description": "a soroban contract to be called by another contract",
"main": "index.js",
"scripts": {
Expand All @@ -23,6 +23,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion cross_contract/contract_b/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"key" : "version",
"value" : "1.0.1"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions cross_contract/contract_b/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contract_b",
"version": "1.0.0",
"version": "1.1.0",
"description": "a contract that calls another soroban contract",
"main": "index.js",
"scripts": {
Expand All @@ -23,6 +23,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.0"
"as-soroban-sdk": "^1.1.0"
}
}
10 changes: 5 additions & 5 deletions custom_account/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as ledger from "as-soroban-sdk/lib/ledger";
import * as address from "as-soroban-sdk/lib/address";
import * as context from "as-soroban-sdk/lib/context";
import * as env from "as-soroban-sdk/lib/env";
import {i128gt, i128sub, isNegative} from "as-soroban-sdk/lib/val128";
import {i128IsGreaterThan, i128Sub, isI128Negative} from "as-soroban-sdk/lib/arithm128";

//! This is a basic multi-sig account contract with a customizable per-token
//! authorization policy.
Expand Down Expand Up @@ -183,14 +183,14 @@ function verify_authorization_policy(context_entry:VecObject, curr_contract_addr
// here, as it's expected to have the standard interface.
let args_vec = new Vec(ctxt_args);
let spent = args_vec.get(2);
if(isNegative(spent)) {
if(isI128Negative(spent)) {
context.failWithErrorCode(ERR_CODE.NEGATIVE_AMOUNT);
}
if (!all_signed && (isNegative(spend_left) || i128gt(spent, spend_left))) {
if (!all_signed && (isI128Negative(spend_left) || i128IsGreaterThan(spent, spend_left))) {
context.failWithErrorCode(ERR_CODE.NOT_ENOUGH_SIGNERS);
}
if (!isNegative(spend_left)) {
spend_left_per_token.put(curr_contract_addr, i128sub(spend_left, spent));
if (!isI128Negative(spend_left)) {
spend_left_per_token.put(curr_contract_addr, i128Sub(spend_left, spent));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion custom_account/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions custom_account/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom_account",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,6 +28,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion deployer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ The concrete argument and return types of this example deployer contract are def
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
2 changes: 1 addition & 1 deletion deployer/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions deployer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deployer",
"version": "1.0.0",
"version": "1.1.0",
"description": "The deployer example demonstrates how to deploy contracts using a contract.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -31,6 +31,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion errors/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions errors/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "error",
"version": "1.0.0",
"version": "1.1.0",
"description": "example of soroban client errors",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,6 +28,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion hello_word/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The concrete types must also be defined in the [contract spec](https://github.co
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
2 changes: 1 addition & 1 deletion hello_word/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions hello_word/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hello_word",
"version": "1.0.0",
"version": "1.1.0",
"description": "hello word example for the as soroban sdk",
"scripts": {
"asbuild:debug": "asc assembly/index.ts --target debug",
Expand All @@ -24,6 +24,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion increment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The concrete types must also be defined in the [contract spec](https://github.co
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
2 changes: 1 addition & 1 deletion increment/contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"key" : "version",
"value" : "1.0.0"
"value" : "1.1.0"
},
{
"key" : "description",
Expand Down
4 changes: 2 additions & 2 deletions increment/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "increment",
"version": "1.0.0",
"version": "1.1.0",
"description": "soroban example using storage to increment",
"scripts": {
"asbuild:release": "asc assembly/index.ts --target release",
Expand All @@ -26,6 +26,6 @@
}
},
"dependencies": {
"as-soroban-sdk": "^1.0.1"
"as-soroban-sdk": "^1.1.0"
}
}
Loading

0 comments on commit 8fbba4d

Please sign in to comment.