From 8fbba4d66369da794de3823aad39c1d5a65566c2 Mon Sep 17 00:00:00 2001 From: Christian Rogobete Date: Mon, 16 Sep 2024 23:39:53 +0200 Subject: [PATCH] update for sdk 1.1.0 - host based 128 bit arithmetics --- README.md | 2 +- add/README.md | 2 +- add/contract.json | 2 +- add/package.json | 4 +- atomic-swap/README.md | 2 +- atomic-swap/assembly/index.ts | 8 +-- atomic-swap/contract.json | 2 +- atomic-swap/package.json | 4 +- auth/contract.json | 2 +- auth/package.json | 4 +- contract_events/contract.json | 2 +- contract_events/package.json | 4 +- cross_contract/contract_a/contract.json | 2 +- cross_contract/contract_a/package.json | 4 +- cross_contract/contract_b/contract.json | 2 +- cross_contract/contract_b/package.json | 4 +- custom_account/assembly/index.ts | 10 ++-- custom_account/contract.json | 2 +- custom_account/package.json | 4 +- deployer/README.md | 2 +- deployer/contract.json | 2 +- deployer/package.json | 4 +- errors/contract.json | 2 +- errors/package.json | 4 +- hello_word/README.md | 2 +- hello_word/contract.json | 2 +- hello_word/package.json | 4 +- increment/README.md | 2 +- increment/contract.json | 2 +- increment/package.json | 4 +- liquidity_pool/assembly/index.ts | 57 ++++++++++--------- liquidity_pool/contract.json | 2 +- liquidity_pool/package.json | 4 +- liquidity_pool/testContract.cjs | 24 ++++---- logging/contract.json | 2 +- logging/package.json | 4 +- multi_swap/assembly/index.ts | 6 +- multi_swap/contract.json | 2 +- multi_swap/package.json | 4 +- single_offer/assembly/index.ts | 6 +- single_offer/contract.json | 2 +- single_offer/package.json | 4 +- testing/contract.json | 2 +- testing/package.json | 4 +- timelock/contract.json | 2 +- timelock/package.json | 4 +- token/README.md | 4 +- token/assembly/allowance.ts | 8 +-- token/assembly/balance.ts | 8 +-- token/assembly/contract.ts | 4 +- token/contract.json | 2 +- token/package.json | 4 +- .../new_contract/contract.json | 2 +- .../new_contract/package.json | 4 +- .../old_contract/contract.json | 2 +- .../old_contract/package.json | 4 +- 56 files changed, 135 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index 6805643..616b2d1 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/add/README.md b/add/README.md index 6e9f65e..7cd2e06 100644 --- a/add/README.md +++ b/add/README.md @@ -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", diff --git a/add/contract.json b/add/contract.json index 9092dd6..cfa5241 100644 --- a/add/contract.json +++ b/add/contract.json @@ -16,7 +16,7 @@ }, { "key" : "version", - "value" : "1.0.1" + "value" : "1.1.0" }, { "key" : "description", diff --git a/add/package.json b/add/package.json index 8731309..65e969d 100644 --- a/add/package.json +++ b/add/package.json @@ -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", @@ -25,6 +25,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/atomic-swap/README.md b/atomic-swap/README.md index ffc0769..f815a69 100644 --- a/atomic-swap/README.md +++ b/atomic-swap/README.md @@ -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()); } ``` diff --git a/atomic-swap/assembly/index.ts b/atomic-swap/assembly/index.ts index 76aab2a..5e20455 100644 --- a/atomic-swap/assembly/index.ts +++ b/atomic-swap/assembly/index.ts @@ -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, @@ -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); } @@ -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()); } \ No newline at end of file diff --git a/atomic-swap/contract.json b/atomic-swap/contract.json index a41a18a..fbcb7a4 100644 --- a/atomic-swap/contract.json +++ b/atomic-swap/contract.json @@ -21,7 +21,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/atomic-swap/package.json b/atomic-swap/package.json index e84216e..94ddaf9 100644 --- a/atomic-swap/package.json +++ b/atomic-swap/package.json @@ -1,6 +1,6 @@ { "name": "atomic_swap", - "version": "1.0.0", + "version": "1.1.0", "description": "atomic swap contract example", "main": "index.js", "scripts": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/auth/contract.json b/auth/contract.json index 720220d..2df5917 100644 --- a/auth/contract.json +++ b/auth/contract.json @@ -16,7 +16,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/auth/package.json b/auth/package.json index 070a2de..e09a0ec 100644 --- a/auth/package.json +++ b/auth/package.json @@ -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": { @@ -23,6 +23,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/contract_events/contract.json b/contract_events/contract.json index 9e327fc..4b28c2c 100644 --- a/contract_events/contract.json +++ b/contract_events/contract.json @@ -13,7 +13,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/contract_events/package.json b/contract_events/package.json index ee2faf7..7b1ec13 100644 --- a/contract_events/package.json +++ b/contract_events/package.json @@ -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": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/cross_contract/contract_a/contract.json b/cross_contract/contract_a/contract.json index 734a20f..0e24de3 100644 --- a/cross_contract/contract_a/contract.json +++ b/cross_contract/contract_a/contract.json @@ -16,7 +16,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/cross_contract/contract_a/package.json b/cross_contract/contract_a/package.json index b717c68..b63a5a2 100644 --- a/cross_contract/contract_a/package.json +++ b/cross_contract/contract_a/package.json @@ -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": { @@ -23,6 +23,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/cross_contract/contract_b/contract.json b/cross_contract/contract_b/contract.json index 7f2a8f6..07d272c 100644 --- a/cross_contract/contract_b/contract.json +++ b/cross_contract/contract_b/contract.json @@ -15,7 +15,7 @@ }, { "key" : "version", - "value" : "1.0.1" + "value" : "1.1.0" }, { "key" : "description", diff --git a/cross_contract/contract_b/package.json b/cross_contract/contract_b/package.json index a4af111..406536f 100644 --- a/cross_contract/contract_b/package.json +++ b/cross_contract/contract_b/package.json @@ -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": { @@ -23,6 +23,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.0" + "as-soroban-sdk": "^1.1.0" } } diff --git a/custom_account/assembly/index.ts b/custom_account/assembly/index.ts index ce911bd..0782d0a 100644 --- a/custom_account/assembly/index.ts +++ b/custom_account/assembly/index.ts @@ -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. @@ -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)); } } } diff --git a/custom_account/contract.json b/custom_account/contract.json index 182deb3..3e6c225 100644 --- a/custom_account/contract.json +++ b/custom_account/contract.json @@ -32,7 +32,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/custom_account/package.json b/custom_account/package.json index 6f8137d..b2b4ae6 100644 --- a/custom_account/package.json +++ b/custom_account/package.json @@ -1,6 +1,6 @@ { "name": "custom_account", - "version": "1.0.0", + "version": "1.1.0", "description": "", "main": "index.js", "scripts": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/deployer/README.md b/deployer/README.md index abb5609..644c6c4 100644 --- a/deployer/README.md +++ b/deployer/README.md @@ -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", diff --git a/deployer/contract.json b/deployer/contract.json index 973a7f5..72bb5d3 100644 --- a/deployer/contract.json +++ b/deployer/contract.json @@ -25,7 +25,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/deployer/package.json b/deployer/package.json index 8df3bae..09f0acf 100644 --- a/deployer/package.json +++ b/deployer/package.json @@ -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": { @@ -31,6 +31,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/errors/contract.json b/errors/contract.json index a7558a2..2d871cb 100644 --- a/errors/contract.json +++ b/errors/contract.json @@ -15,7 +15,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/errors/package.json b/errors/package.json index be585ca..860567c 100644 --- a/errors/package.json +++ b/errors/package.json @@ -1,6 +1,6 @@ { "name": "error", - "version": "1.0.0", + "version": "1.1.0", "description": "example of soroban client errors", "main": "index.js", "scripts": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/hello_word/README.md b/hello_word/README.md index 62ff6a7..f324992 100644 --- a/hello_word/README.md +++ b/hello_word/README.md @@ -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", diff --git a/hello_word/contract.json b/hello_word/contract.json index 76df7de..08fbf9e 100644 --- a/hello_word/contract.json +++ b/hello_word/contract.json @@ -13,7 +13,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/hello_word/package.json b/hello_word/package.json index bae207f..441c182 100644 --- a/hello_word/package.json +++ b/hello_word/package.json @@ -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", @@ -24,6 +24,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/increment/README.md b/increment/README.md index bdc82d2..dbd1dbb 100644 --- a/increment/README.md +++ b/increment/README.md @@ -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", diff --git a/increment/contract.json b/increment/contract.json index bd1f669..0acdfee 100644 --- a/increment/contract.json +++ b/increment/contract.json @@ -13,7 +13,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/increment/package.json b/increment/package.json index b8d9746..238d427 100644 --- a/increment/package.json +++ b/increment/package.json @@ -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", @@ -26,6 +26,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/liquidity_pool/assembly/index.ts b/liquidity_pool/assembly/index.ts index b4b4707..c595437 100644 --- a/liquidity_pool/assembly/index.ts +++ b/liquidity_pool/assembly/index.ts @@ -7,7 +7,8 @@ import { Vec } from "as-soroban-sdk/lib/vec"; import { Bytes} from "as-soroban-sdk/lib/bytes"; import { Sym } from "as-soroban-sdk/lib/sym"; import { __deposit_b, get_deposit_amounts } from "./deposit"; -import { i128add, i128div, i128gt, i128le, i128lt, i128mul, i128muldiv, i128sqrt, i128sub } from "as-soroban-sdk/lib/val128"; +import { i128Add, i128Div, i128IsGreaterThan, i128IsLowerThan, i128IsEqual, i128Mul, i128MulDiv, i128Sub } from "as-soroban-sdk/lib/arithm128"; +import {i128sqrt} from "as-soroban-sdk/lib/val128"; import { call, create_contract, serialize_to_bytes } from "as-soroban-sdk/lib/env"; @@ -97,20 +98,20 @@ export function deposit(to: AddressObject, desired_a: I128Val, min_a: I128Val, d let zero = fromI128Small(0); let new_total_shares = zero; - if (i128gt(reserve_a, zero) && i128gt(reserve_b, zero)) { - let shares_a = i128muldiv(balance_a, total_shares, reserve_a); - let shares_b = i128muldiv(balance_b, total_shares, reserve_b); - if(i128le(shares_a, shares_b)) { + if (i128IsGreaterThan(reserve_a, zero) && i128IsGreaterThan(reserve_b, zero)) { + let shares_a = i128MulDiv(balance_a, total_shares, reserve_a); + let shares_b = i128MulDiv(balance_b, total_shares, reserve_b); + if(i128IsLowerThan(shares_a, shares_b) || i128IsEqual(shares_a, shares_b)) { new_total_shares = shares_a; } else { new_total_shares = shares_b; } } else { - let mul = i128mul(balance_a, balance_b); + let mul = i128Mul(balance_a, balance_b); new_total_shares = i128sqrt(mul); } - mint_shares(to, i128sub(new_total_shares, total_shares)); + mint_shares(to, i128Sub(new_total_shares, total_shares)); put_reserve_a(balance_a); put_reserve_b(balance_b); @@ -137,10 +138,10 @@ export function swap(to: AddressObject, buy_a: U32Val, out: I128Val, in_max: I12 // First calculate how much needs to be sold to buy amount out from the pool - let n = i128mul(i128mul(reserve_sell, out), fromI128Small(1000)); - let d = i128mul(i128sub(reserve_buy, out), fromI128Small(997)); - let sell_amount = i128add(i128div(n,d), fromI128Small(1)); - if (i128gt(sell_amount, in_max)) { + let n = i128Mul(i128Mul(reserve_sell, out), fromI128Small(1000)); + let d = i128Mul(i128Sub(reserve_buy, out), fromI128Small(997)); + let sell_amount = i128Add(i128Div(n,d), fromI128Small(1)); + if (i128IsGreaterThan(sell_amount, in_max)) { context.failWithErrorCode(ERR_CODES.IN_AMOUNT_IS_OVER_MAX); } @@ -178,10 +179,10 @@ export function swap(to: AddressObject, buy_a: U32Val, out: I128Val, in_max: I12 let new_inv_a = invariant_factor(balance_a, reserve_a, out_a, residue_numerator, residue_denominator); let new_inv_b = invariant_factor(balance_b, reserve_b, out_b, residue_numerator, residue_denominator); - let old_inv_a = i128mul(residue_denominator, reserve_a); - let old_inv_b = i128mul(residue_denominator, reserve_b); + let old_inv_a = i128Mul(residue_denominator, reserve_a); + let old_inv_b = i128Mul(residue_denominator, reserve_b); - if (i128lt(i128mul(new_inv_a, new_inv_b), i128mul(old_inv_a, old_inv_b))) { // new_inv_a * new_inv_b < old_inv_a * old_inv_b + if (i128IsLowerThan(i128Mul(new_inv_a, new_inv_b), i128Mul(old_inv_a, old_inv_b))) { // new_inv_a * new_inv_b < old_inv_a * old_inv_b context.failWithErrorCode(ERR_CODES.CONST_PROD_INVARIANT_DOESE_NOT_HOLD); } @@ -191,8 +192,8 @@ export function swap(to: AddressObject, buy_a: U32Val, out: I128Val, in_max: I12 transfer_b(to, out_b); } - put_reserve_a(i128sub(balance_a, out_a)); - put_reserve_b(i128sub(balance_b, out_b)); + put_reserve_a(i128Sub(balance_a, out_a)); + put_reserve_b(i128Sub(balance_b, out_b)); return fromVoid(); } @@ -218,18 +219,18 @@ export function withdraw(to: AddressObject, share_amount: I128Val, min_a: I128Va let total_shares = get_total_shares(); // Now calculate the withdraw amounts - let out_a = i128muldiv(balance_a, balance_shares, total_shares); - let out_b = i128muldiv(balance_b, balance_shares, total_shares); + let out_a = i128MulDiv(balance_a, balance_shares, total_shares); + let out_b = i128MulDiv(balance_b, balance_shares, total_shares); - if (i128lt(out_a, min_a) || i128lt(out_b, min_b)) { + if (i128IsLowerThan(out_a, min_a) || i128IsLowerThan(out_b, min_b)) { context.failWithErrorCode(ERR_CODES.MIN_NOT_SATISFIED); } burn_shares(balance_shares); transfer_a(to, out_a); transfer_b(to, out_b); - put_reserve_a(i128sub(balance_a, out_a)); - put_reserve_b(i128sub(balance_b, out_b)); + put_reserve_a(i128Sub(balance_a, out_a)); + put_reserve_b(i128Sub(balance_b, out_b)); let result = new Vec(); result.pushBack(out_a); @@ -325,7 +326,7 @@ function mint_shares(to: AddressObject, amount: I128Val) : void { mintArgs.pushBack(amount); call(share_contract, fromSmallSymbolStr("mint"), mintArgs.getHostObject()); - put_total_shares(i128add(total, amount)); + put_total_shares(i128Add(total, amount)); } @@ -339,24 +340,24 @@ function burn_shares(amount: I128Val) : void { burnArgs.pushBack(amount); call(share_contract, fromSmallSymbolStr("burn"), burnArgs.getHostObject()); - put_total_shares(i128sub(total, amount)); + put_total_shares(i128Sub(total, amount)); } function invariant_factor(balance: I128Val, reserve: I128Val, out:I128Val, residue_numerator: I128Val, residue_denominator:I128Val) : I128Val { - let delta = i128sub(i128sub(balance, reserve), out); + let delta = i128Sub(i128Sub(balance, reserve), out); let zero = fromI128Small(0); let adj_delta = zero; - if (i128gt(delta,zero)) { - adj_delta = i128mul(residue_numerator, delta); + if (i128IsGreaterThan(delta,zero)) { + adj_delta = i128Mul(residue_numerator, delta); } else { - adj_delta = i128mul(residue_denominator, delta); + adj_delta = i128Mul(residue_denominator, delta); } - return i128add(i128mul(residue_denominator, reserve), adj_delta); + return i128Add(i128Mul(residue_denominator, reserve), adj_delta); } function transfer(contract_id: BytesObject, to: AddressObject, amount: I128Val) : void { diff --git a/liquidity_pool/contract.json b/liquidity_pool/contract.json index 4367885..3c3d811 100644 --- a/liquidity_pool/contract.json +++ b/liquidity_pool/contract.json @@ -58,7 +58,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/liquidity_pool/package.json b/liquidity_pool/package.json index edf5ed8..3113a94 100644 --- a/liquidity_pool/package.json +++ b/liquidity_pool/package.json @@ -1,6 +1,6 @@ { "name": "liquidity_pool", - "version": "1.0.0", + "version": "1.1.0", "description": "liquidity pool example", "main": "index.js", "scripts": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/liquidity_pool/testContract.cjs b/liquidity_pool/testContract.cjs index e84ac84..3d69daf 100644 --- a/liquidity_pool/testContract.cjs +++ b/liquidity_pool/testContract.cjs @@ -147,7 +147,7 @@ async function buildLPContract() { async function deployContract(invoker, path) { try { console.log("deploy contract " + path + " ...") - let cmd = 'soroban contract deploy' + let cmd = 'stellar contract deploy' + ' --wasm ' + path + ' --source ' + invoker + ' --rpc-url ' + rpcUrl + @@ -188,7 +188,7 @@ async function buildTokenContract() { async function installTokenContract(invoker) { try { console.log("install token contract ..."); - const { error, stdout, stderr } = await exec('soroban contract install --wasm ../token/build/release.wasm ' + + const { error, stdout, stderr } = await exec('stellar contract install --wasm ../token/build/release.wasm ' + '--source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase); @@ -215,7 +215,7 @@ async function installTokenContract(invoker) { async function initializeLP(invoker, lp_contract_id, token_wasm_hash , token_a, token_b) { console.log("init lp contract ..."); - let cmd = 'soroban -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + + let cmd = 'stellar -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase +' --id ' + lp_contract_id + ' -- initialize --token_wasm_hash ' + token_wasm_hash + ' --token_a '+ token_a + ' --token_b ' + token_b; @@ -233,7 +233,7 @@ async function initializeLP(invoker, lp_contract_id, token_wasm_hash , token_a, async function depositLP(invoker, user_id, lp_contract_id, desired_a, min_a, desired_b, min_b) { console.log("deposit lp ..."); - let cmd = 'soroban -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + + let cmd = 'stellar -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase +' --id ' + lp_contract_id + ' --fee 1000000 -- deposit --to ' + user_id + ' --desired_a '+ desired_a + ' --min_a ' + min_a @@ -252,7 +252,7 @@ async function depositLP(invoker, user_id, lp_contract_id, desired_a, min_a, des async function swapLP(invoker, user_id, lp_contract_id, buy_a, out, in_max) { console.log("swap lp ..."); - let cmd = 'soroban -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + + let cmd = 'stellar -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase +' --id ' + lp_contract_id + ' --fee 1000000 -- swap --to ' + user_id + ' --buy_a '+ buy_a + ' --out ' + out @@ -271,7 +271,7 @@ async function swapLP(invoker, user_id, lp_contract_id, buy_a, out, in_max) { async function withdrawLP(invoker, user_id, lp_contract_id, share_amount, min_a, min_b) { console.log("withdraw lp ..."); - let cmd = 'soroban -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + + let cmd = 'stellar -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase +' --id ' + lp_contract_id + ' --fee 1000000 -- withdraw --to ' + user_id + ' --share_amount '+ share_amount + ' --min_a ' + min_a @@ -290,7 +290,7 @@ async function withdrawLP(invoker, user_id, lp_contract_id, share_amount, min_a, async function get_share_addr(invoker, lp_contract_id) { console.log("get share addr lp ..."); - let cmd = 'soroban -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + + let cmd = 'stellar -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase +' --id ' + lp_contract_id + ' -- share_addr'; @@ -307,7 +307,7 @@ async function get_share_addr(invoker, lp_contract_id) { async function createToken(invoker, adminId, token_contract_id, name , symbol) { console.log("create token ..."); - let cmd = 'soroban -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + + let cmd = 'stellar -q contract invoke --source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase +' --id ' + token_contract_id + ' -- initialize --admin ' + adminId + ' --decimal 8 --name '+ name + ' --symbol ' + symbol; @@ -325,7 +325,7 @@ async function createToken(invoker, adminId, token_contract_id, name , symbol) { async function mint(invoker, to, amount, token_contract_id) { console.log("mint ..."); - const { error, stdout, stderr } = await exec('soroban -q contract invoke' + + const { error, stdout, stderr } = await exec('stellar -q contract invoke' + ' --source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase +' --id ' + token_contract_id + ' -- mint --to ' + to + ' --amount ' + amount); @@ -341,7 +341,7 @@ async function mint(invoker, to, amount, token_contract_id) { async function getBalance(invoker, user, token_contract_id) { console.log("get balance ..."); - let cmd = 'soroban -q contract invoke ' + + let cmd = 'stellar -q contract invoke ' + '--source ' + invoker + ' --rpc-url ' + rpcUrl + ' --network-passphrase ' + networkPassphrase + ' --id ' + token_contract_id + ' -- balance --id ' + user; @@ -358,8 +358,8 @@ async function getBalance(invoker, user, token_contract_id) { } async function generateIdentity(name) { - const { error, stdout, stderr } = await exec('soroban config identity generate ' + network - + name + ' && soroban config identity address ' + name); + const { error, stdout, stderr } = await exec('stellar keys generate ' + network + + name + ' && stellar keys address ' + name); if (error) { assert.fail(`error: ${error.message}`); } diff --git a/logging/contract.json b/logging/contract.json index 6a2ff9f..8659056 100644 --- a/logging/contract.json +++ b/logging/contract.json @@ -13,7 +13,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/logging/package.json b/logging/package.json index c673850..fb83ff8 100644 --- a/logging/package.json +++ b/logging/package.json @@ -1,6 +1,6 @@ { "name": "logging", - "version": "1.0.0", + "version": "1.1.0", "description": "soroban contract example that logs data on the host for debugging purposes - soroban cli only", "main": "index.js", "scripts": { @@ -23,6 +23,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/multi_swap/assembly/index.ts b/multi_swap/assembly/index.ts index f8c3629..380755a 100644 --- a/multi_swap/assembly/index.ts +++ b/multi_swap/assembly/index.ts @@ -1,6 +1,7 @@ import { AddressObject, VecObject, VoidVal, fromVoid} from "as-soroban-sdk/lib/value"; import { Vec } from "as-soroban-sdk/lib/vec"; -import { i128ge, i128le} from "as-soroban-sdk/lib/val128"; +//import { i128ge, i128le} from "as-soroban-sdk/lib/val128"; +import { i128IsEqual, i128IsGreaterThan, i128IsLowerThan} from "as-soroban-sdk/lib/arithm128"; import * as contract from "as-soroban-sdk/lib/contract"; import * as address from "as-soroban-sdk/lib/address"; @@ -64,7 +65,8 @@ export function multi_swap(swap_contract: AddressObject, token_a: AddressObject, let amountB = swapB.get(DATA_INDEX.AMOUNT); let minRecvB = swapB.get(DATA_INDEX.MIN_RECV); - if (i128ge(amountA, minRecvB) && i128le(minRecvA, amountB)) { + if ((i128IsGreaterThan(amountA, minRecvB) || i128IsEqual(amountA, minRecvB)) && + (i128IsLowerThan(minRecvA, amountB) || i128IsEqual(minRecvA, amountB))) { // As this is a simple 'batching' contract, there is no need // for all possible swaps to be fulfilled, hence we just want // to demonstrate how authorized calls can be batched together. diff --git a/multi_swap/contract.json b/multi_swap/contract.json index 8e68260..7e930fc 100644 --- a/multi_swap/contract.json +++ b/multi_swap/contract.json @@ -19,7 +19,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/multi_swap/package.json b/multi_swap/package.json index 073e8ee..9236870 100644 --- a/multi_swap/package.json +++ b/multi_swap/package.json @@ -1,6 +1,6 @@ { "name": "multi_swap", - "version": "1.0.0", + "version": "1.1.0", "description": "This example demonstrates how authorized calls can be batched together.", "main": "index.js", "scripts": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/single_offer/assembly/index.ts b/single_offer/assembly/index.ts index 93634c3..ebee424 100644 --- a/single_offer/assembly/index.ts +++ b/single_offer/assembly/index.ts @@ -19,7 +19,7 @@ import * as contract from "as-soroban-sdk/lib/contract"; import * as address from "as-soroban-sdk/lib/address"; import { has_offer, write_offer, load_offer, __sell_price, __buy_price, __buy_token, __sell_token, __seller } from "./offer"; import { Vec } from "as-soroban-sdk/lib/vec"; -import { i128lt, i128muldiv } from "as-soroban-sdk/lib/val128"; +import { i128IsLowerThan, i128MulDiv } from "as-soroban-sdk/lib/arithm128"; enum ERR_CODE { OFFER_ALREADY_EXISTS = 1, @@ -74,9 +74,9 @@ export function trade(buyer: AddressObject, buy_token_amount: I128Val, min_sell_ // Compute the amount of token that buyer needs to receive. let sell_price = fromI128Small(toU32(__sell_price) as u64); let buy_price = fromI128Small(toU32(__buy_price) as u64); - let sell_token_amount = i128muldiv(buy_token_amount, sell_price, buy_price); + let sell_token_amount = i128MulDiv(buy_token_amount, sell_price, buy_price); - if (i128lt(sell_token_amount, min_sell_token_amount)) { + if (i128IsLowerThan(sell_token_amount, min_sell_token_amount)) { context.failWithErrorCode(ERR_CODE.PRICE_IS_TOO_LOW); } diff --git a/single_offer/contract.json b/single_offer/contract.json index 65bde7f..74f7a1e 100644 --- a/single_offer/contract.json +++ b/single_offer/contract.json @@ -49,7 +49,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/single_offer/package.json b/single_offer/package.json index f34ab5f..187c716 100644 --- a/single_offer/package.json +++ b/single_offer/package.json @@ -1,6 +1,6 @@ { "name": "single_offer", - "version": "1.0.0", + "version": "1.1.0", "description": "single offer as example", "main": "index.js", "scripts": { @@ -29,6 +29,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/testing/contract.json b/testing/contract.json index f021f39..cfa5241 100644 --- a/testing/contract.json +++ b/testing/contract.json @@ -16,7 +16,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/testing/package.json b/testing/package.json index 810f3ae..20bec6e 100644 --- a/testing/package.json +++ b/testing/package.json @@ -1,6 +1,6 @@ { "name": "testing", - "version": "1.0.0", + "version": "1.1.0", "description": "show how to test a contracts function", "main": "index.js", "scripts": { @@ -21,6 +21,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/timelock/contract.json b/timelock/contract.json index 1f6f155..3bf0830 100644 --- a/timelock/contract.json +++ b/timelock/contract.json @@ -25,7 +25,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/timelock/package.json b/timelock/package.json index 0ee7bd1..01da992 100644 --- a/timelock/package.json +++ b/timelock/package.json @@ -1,6 +1,6 @@ { "name": "timelock", - "version": "1.0.0", + "version": "1.1.0", "description": "timelock contract example", "main": "index.js", "scripts": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/token/README.md b/token/README.md index 772f872..d741aa6 100644 --- a/token/README.md +++ b/token/README.md @@ -86,8 +86,8 @@ export function transfer(from: AddressObject, to: AddressObject, amount:I128Val) spend_balance(from, amount); // We calculate some new amounts for payment and royalty - let payment = i128div(i128mul(amount, fromI128Small(997)), fromI128Small(1000)); - let royalty = i128sub(amount, payment); + let payment = i128Div(i128Mul(amount, fromI128Small(997)), fromI128Small(1000)); + let royalty = i128Sub(amount, payment); receive_balance(artist, royalty); receive_balance(to, payment); ev_trans(from, to, amount); diff --git a/token/assembly/allowance.ts b/token/assembly/allowance.ts index 833a32f..7e3de27 100644 --- a/token/assembly/allowance.ts +++ b/token/assembly/allowance.ts @@ -2,7 +2,7 @@ import * as ledger from "as-soroban-sdk/lib/ledger"; import * as context from "as-soroban-sdk/lib/context"; import {Map} from "as-soroban-sdk/lib/map"; import { AddressObject, fromI128Small, fromSmallSymbolStr, fromU32, I128Val, storageTypeTemporary, toU32, U32Val } from "as-soroban-sdk/lib/value"; -import { i128lt, i128sub, i128gt } from "as-soroban-sdk/lib/val128"; +import { i128IsLowerThan, i128Sub, i128IsGreaterThan } from "as-soroban-sdk/lib/arithm128"; import { ERR_CODE, S_ALLOWANCE } from "./util"; import { Vec } from "as-soroban-sdk/lib/vec"; import { extend_contract_data_ttl } from "as-soroban-sdk/lib/env"; @@ -37,7 +37,7 @@ export function read_allowance(from: AddressObject, spender:AddressObject): Vec export function write_allowance(from: AddressObject, spender:AddressObject, amount: I128Val, expirationLedger: U32Val): void { - let amountGtZero = i128gt(amount, fromI128Small(0)); + let amountGtZero = i128IsGreaterThan(amount, fromI128Small(0)); let currentLedgerSequence = context.getLedgerSequence(); if (amountGtZero && toU32(expirationLedger) < currentLedgerSequence) { @@ -87,9 +87,9 @@ export function spend_allowance(from: AddressObject, spender:AddressObject, amou let allowance = read_allowance(from, spender); let allowanceAmount = allowance.get(0); - if (i128lt(allowanceAmount, amount)) { + if (i128IsLowerThan(allowanceAmount, amount)) { context.failWithErrorCode(ERR_CODE.INSUFFICIENT_ALLOWANCE); } - write_allowance(from, spender, i128sub(allowanceAmount, amount), allowance.get(1)); + write_allowance(from, spender, i128Sub(allowanceAmount, amount), allowance.get(1)); } diff --git a/token/assembly/balance.ts b/token/assembly/balance.ts index 22fa393..d61d82d 100644 --- a/token/assembly/balance.ts +++ b/token/assembly/balance.ts @@ -3,7 +3,7 @@ import * as context from "as-soroban-sdk/lib/context"; import { AddressObject, fromI128Small, fromSmallSymbolStr, fromU32, I128Val, storageTypePersistent } from "as-soroban-sdk/lib/value"; import {Map} from "as-soroban-sdk/lib/map"; import { ERR_CODE, S_BALANCE } from "./util"; -import { i128lt, i128sub, i128add } from "as-soroban-sdk/lib/val128"; +import { i128IsLowerThan, i128Sub, i128Add } from "as-soroban-sdk/lib/arithm128"; import { extend_contract_data_ttl } from "as-soroban-sdk/lib/env"; const BALANCE_BUMP_AMOUNT = 518400; // 30 days @@ -39,13 +39,13 @@ export function write_balance(addr: AddressObject, amount: I128Val): void { export function receive_balance(addr: AddressObject, amount: I128Val): void { let balance = read_balance(addr); - write_balance(addr, i128add(balance, amount)); + write_balance(addr, i128Add(balance, amount)); } export function spend_balance(addr: AddressObject, amount: I128Val): void { let balance = read_balance(addr); - if (i128lt(balance, amount)) { + if (i128IsLowerThan(balance, amount)) { context.failWithErrorCode(ERR_CODE.INSUFFICIENT_BALANCE); } - write_balance(addr, i128sub(balance, amount)); + write_balance(addr, i128Sub(balance, amount)); } \ No newline at end of file diff --git a/token/assembly/contract.ts b/token/assembly/contract.ts index 5e5d7c5..45a4d30 100644 --- a/token/assembly/contract.ts +++ b/token/assembly/contract.ts @@ -7,7 +7,7 @@ import { read_decimal, read_name, read_symbol, write_metadata } from "./metadata import { read_allowance, spend_allowance, write_allowance } from "./allowance"; import { ev_burn, ev_approve, ev_mint, ev_s_admin, ev_trans } from "./events"; import { read_balance, receive_balance, spend_balance } from "./balance"; -import { isNegative } from "as-soroban-sdk/lib/val128"; +import { isI128Negative } from "as-soroban-sdk/lib/arithm128"; import { extend_current_contract_instance_and_code_ttl } from "as-soroban-sdk/lib/env"; const INSTANCE_BUMP_AMOUNT = 120960; // 7 days @@ -57,7 +57,7 @@ function bumpInstanceAndCode(): void { } function checkNonNegative(amount:I128Val): void { - if (isNegative(amount)){ + if (isI128Negative(amount)){ context.failWithErrorCode(ERR_CODE.NEG_AMOUNT_NOT_ALLOWED); } } diff --git a/token/contract.json b/token/contract.json index c1771d1..be2e47c 100644 --- a/token/contract.json +++ b/token/contract.json @@ -115,7 +115,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/token/package.json b/token/package.json index fcf0667..d72f2bb 100644 --- a/token/package.json +++ b/token/package.json @@ -1,6 +1,6 @@ { "name": "token", - "version": "1.0.0", + "version": "1.1.0", "description": "Token example", "main": "index.js", "scripts": { @@ -27,6 +27,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/upgradeable_contract/new_contract/contract.json b/upgradeable_contract/new_contract/contract.json index bae4235..fc20d5f 100644 --- a/upgradeable_contract/new_contract/contract.json +++ b/upgradeable_contract/new_contract/contract.json @@ -30,7 +30,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/upgradeable_contract/new_contract/package.json b/upgradeable_contract/new_contract/package.json index 9ba4bd8..2153940 100644 --- a/upgradeable_contract/new_contract/package.json +++ b/upgradeable_contract/new_contract/package.json @@ -1,6 +1,6 @@ { "name": "new_contract", - "version": "1.0.0", + "version": "1.1.0", "description": "upgradable soroban contract", "main": "index.js", "scripts": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } } diff --git a/upgradeable_contract/old_contract/contract.json b/upgradeable_contract/old_contract/contract.json index 785d205..1240ee6 100644 --- a/upgradeable_contract/old_contract/contract.json +++ b/upgradeable_contract/old_contract/contract.json @@ -25,7 +25,7 @@ }, { "key" : "version", - "value" : "1.0.0" + "value" : "1.1.0" }, { "key" : "description", diff --git a/upgradeable_contract/old_contract/package.json b/upgradeable_contract/old_contract/package.json index 4c9d01c..515eb1a 100644 --- a/upgradeable_contract/old_contract/package.json +++ b/upgradeable_contract/old_contract/package.json @@ -1,6 +1,6 @@ { "name": "old_contract", - "version": "1.0.0", + "version": "1.1.0", "description": "upgradable contract example", "main": "index.js", "scripts": { @@ -28,6 +28,6 @@ } }, "dependencies": { - "as-soroban-sdk": "^1.0.1" + "as-soroban-sdk": "^1.1.0" } }