Skip to content

Commit

Permalink
Merge pull request #125 from kommitters/v0.14
Browse files Browse the repository at this point in the history
Release v0.14.0
  • Loading branch information
Odraxs authored Sep 5, 2023
2 parents b0b4ff5 + 72aadd2 commit b141268
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
otp: ["24.3.4.9"]
elixir: ["1.14.0"]
otp: ["25.3.2.5"]
elixir: ["1.14.5"]
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
steps:
Expand All @@ -29,7 +29,7 @@ jobs:
repo.hex.pm:443
builds.hex.pm:443
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
with:
otp-version: ${{ matrix.otp }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
otp: ["24.3.4.9"]
elixir: ["1.14.0"]
otp: ["25.3.2.5"]
elixir: ["1.14.5"]
env:
MIX_ENV: test
steps:
Expand All @@ -32,12 +32,12 @@ jobs:
repo.hex.pm:443
builds.hex.pm:443
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
id: beam
with:
otp-version: "24"
elixir-version: "1.14.0"
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: deps
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@cba0d00b1fc9a034e1e642ea0f1103c282990604 # v2.5.0
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
with:
disable-sudo: true
egress-policy: block
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@cba0d00b1fc9a034e1e642ea0f1103c282990604 # v2.5.0
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
with:
disable-sudo: true
egress-policy: block
Expand All @@ -37,7 +37,7 @@ jobs:
oss-fuzz-build-logs.storage.googleapis.com:443
- name: "Checkout code"
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
persist-credentials: false

Expand Down Expand Up @@ -69,6 +69,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3
uses: github/codeql-action/upload-sarif@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
elixir 1.14.0
elixir 1.14.5
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.14.0 (05.09.2023)

- Allow to add custom extra fee rate when invoking functions.
- Update all dependencies.

## 0.13.0 (09.08.2023)

- [Allow invocation with invoker authorization](https://github.com/kommitters/soroban.ex/issues/103).
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
```elixir
def deps do
[
{:soroban, "~> 0.13.0"}
{:soroban, "~> 0.14.0"}
]
end
```
Expand Down Expand Up @@ -477,6 +477,7 @@ The deployment and invocation of Soroban smart contracts is done through the `So
- `source_secret_key`: Secret key of the function invoker responsible for signing the transaction.
- `function_name`: String indicating the name of the function to be invoked.
- `function_args`: List of `Soroban.Types` representing the arguments required by the indicated function (`function_name`). They should be provided in the specific order expected by the function.
- `extra_fee_rate`: Float number to increment the transaction fee to pay, useful when the operation returns an insufficient fee error.
- `auth_secret_key`: (optional) Secret key used to authorize the function invocation when the function invoker is not the same function authorizer.

##### Simple invocation - no authorization required
Expand Down Expand Up @@ -543,6 +544,7 @@ Contract.invoke(contract_address, source_secret_key, function_name, function_arg

contract_address = "CD43KXYLGORRXFATEUD3OKOQG4PIKLFL55FRETM3CPHI2WUF2NMFIEUM"
source_secret_key = "SDRD4CSRGPWUIPRDS5O3CJBNJME5XVGWNI677MZDD4OD2ZL2R6K5IQ24"
extra_fee_rate = 0.05
function_name = "swap"

function_args = [
Expand All @@ -562,6 +564,7 @@ Contract.invoke(contract_address, source_secret_key, function_name, function_arg
source_secret_key,
function_name,
function_args,
extra_fee_rate,
auth_secret_keys
)

Expand Down Expand Up @@ -883,13 +886,15 @@ This XDR is required by wallets to sign transactions before they can be submitte
- `source_public_key`: Public key of the function invoker responsible for signing the transaction.
- `function_name`: String value indicating the name of the function to be invoked.
- `function_args`: List of `Soroban.Types` representing the arguments required by the indicated function (`function_name`). They should be provided in the specific order expected by the function.
- `extra_fee_rate`: Float number to increment the transaction fee to pay, useful when the operation returns an insufficient fee error.

```elixir
alias Soroban.Contract
alias Soroban.Types.String

contract_address = "CD3HNKU3ERTEYLBBBVTSOYE4ZL2ZWV7NHLQIZRRKC4CBNMZXC7ISBXHV"
source_public_key = "GDEU46HFMHBHCSFA3K336I3MJSBZCWVI3LUGSNL6AF2BW2Q2XR7NNAPM"
extra_fee_rate = 0.05
function_name = "hello"

function_args = [String.new("world")]
Expand All @@ -898,7 +903,8 @@ Contract.retrieve_unsigned_xdr_to_invoke(
contract_address,
source_public_key,
function_name,
function_args
function_args,
extra_fee_rate
)

"AAAAAgAAAAD...QAAAAAAAAAAAAAAAAAAAAA="
Expand Down
4 changes: 3 additions & 1 deletion lib/contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule Soroban.Contract do
source_secret_key,
function_name,
function_args \\ [],
extra_fee_rate \\ 0.0,
auth_secret_keys \\ []
),
to: InvokeContractFunction,
Expand Down Expand Up @@ -80,7 +81,8 @@ defmodule Soroban.Contract do
contract_address,
source_public_key,
function_name,
function_args \\ []
function_args \\ [],
extra_fee_rate \\ 0.0
),
to: InvokeContractFunction,
as: :retrieve_unsigned_xdr_to_invoke
Expand Down
18 changes: 14 additions & 4 deletions lib/contract/invoke_contract_function.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ defmodule Soroban.Contract.InvokeContractFunction do
source_secret_key :: source_secret_key(),
function_name :: function_name(),
function_args :: function_args(),
extra_fee_rate :: float(),
auth_secret_keys :: auth_secret_keys()
) :: send_response()
def invoke(
contract_address,
source_secret_key,
function_name,
function_args,
extra_fee_rate \\ 0.0,
auth_secret_keys \\ []
) do
with {public_key, _secret} = keypair <- Stellar.KeyPair.from_secret_seed(source_secret_key),
Expand All @@ -63,7 +65,8 @@ defmodule Soroban.Contract.InvokeContractFunction do
sequence_number,
signature,
invoke_host_function_op,
auth_secret_keys
auth_secret_keys,
extra_fee_rate
)
end
end
Expand All @@ -72,13 +75,15 @@ defmodule Soroban.Contract.InvokeContractFunction do
contract_address :: contract_address(),
source_public_key :: source_public_key(),
function_name :: function_name(),
function_args :: function_args()
function_args :: function_args(),
extra_fee_rate :: float()
) :: envelope_xdr()
def retrieve_unsigned_xdr_to_invoke(
contract_address,
source_public_key,
function_name,
function_args
function_args,
extra_fee_rate \\ 0.0
) do
with {:ok, seq_num} <- Accounts.fetch_next_sequence_number(source_public_key),
{:ok, function_args} <- convert_to_sc_val(function_args),
Expand All @@ -93,7 +98,12 @@ defmodule Soroban.Contract.InvokeContractFunction do
) do
invoke_host_function_op
|> RPCCalls.simulate(source_account, sequence_number)
|> RPCCalls.retrieve_unsigned_xdr(source_account, sequence_number, invoke_host_function_op)
|> RPCCalls.retrieve_unsigned_xdr(
source_account,
sequence_number,
invoke_host_function_op,
extra_fee_rate
)
end
end

Expand Down
50 changes: 37 additions & 13 deletions lib/contract/rpc_calls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Soroban.Contract.RPCCalls do
@type validation :: {:ok, any()}
@type account :: Account.t()
@type auths :: list(String.t()) | nil
@type auth_secret_key :: String.t() | nil
@type auth_secret_key :: String.t() | list() | nil
@type envelope_xdr :: String.t()
@type footprint_operations :: BumpFootprintExpiration.t() | RestoreFootprint.t()
@type operation :: InvokeHostFunction.t() | footprint_operations()
Expand Down Expand Up @@ -71,15 +71,18 @@ defmodule Soroban.Contract.RPCCalls do
source_account :: account(),
sequence_number :: sequence_number(),
signature :: signature(),
operation :: operation()
operation :: operation(),
auth_secret_key :: auth_secret_key(),
extra_fee_rate :: float()
) :: send_response() | simulate_response()
def send_transaction(
_simulate_transaction,
_source_account,
_sequence_number,
_signature,
_invoke_host_function_op,
auth_secret_key \\ nil
auth_secret_key \\ nil,
extra_fee_rate \\ 0.0
)

def send_transaction(
Expand All @@ -93,7 +96,8 @@ defmodule Soroban.Contract.RPCCalls do
sequence_number,
signature,
%InvokeHostFunction{} = operation,
auth_secret_keys
auth_secret_keys,
extra_fee_rate
) do
with %InvokeHostFunction{} = invoke_host_function_op <-
set_host_function_auth(operation, auth, auth_secret_keys) do
Expand All @@ -105,7 +109,7 @@ defmodule Soroban.Contract.RPCCalls do
)

%BaseFee{fee: base_fee} = BaseFee.new()
fee = BaseFee.new(base_fee + min_resource_fee + round(min_resource_fee * 0.05))
fee = BaseFee.new(base_fee + min_resource_fee + round(min_resource_fee * extra_fee_rate))

{:ok, envelope_xdr} =
source_account
Expand All @@ -131,7 +135,8 @@ defmodule Soroban.Contract.RPCCalls do
sequence_number,
signature,
operation,
_auth_secret_keys
_auth_secret_keys,
extra_fee_rate
)
when is_list(results) do
with {:ok, operation} <- validate_operation(operation) do
Expand All @@ -143,7 +148,7 @@ defmodule Soroban.Contract.RPCCalls do
)

%BaseFee{fee: base_fee} = BaseFee.new()
fee = BaseFee.new(base_fee + min_resource_fee)
fee = BaseFee.new(base_fee + min_resource_fee + round(min_resource_fee * extra_fee_rate))

{:ok, envelope_xdr} =
source_account
Expand All @@ -164,16 +169,26 @@ defmodule Soroban.Contract.RPCCalls do
_sequence_number,
_signature,
_invoke_host_function_op,
_auth_secret_key
_auth_secret_key,
_extra_fee_rate
),
do: response

@spec retrieve_unsigned_xdr(
simulate_response :: simulate_response(),
source_account :: account(),
sequence_number :: sequence_number(),
invoke_host_function_op :: operation()
invoke_host_function_op :: operation(),
extra_fee_rate :: float()
) :: envelope_xdr() | simulate_response()
def retrieve_unsigned_xdr(
_simulate_response,
_source_account,
_sequence_number,
_invoke_host_function_op,
extra_fee_rate \\ 0.0
)

def retrieve_unsigned_xdr(
{:ok,
%SimulateTransactionResponse{
Expand All @@ -183,9 +198,10 @@ defmodule Soroban.Contract.RPCCalls do
}},
source_account,
sequence_number,
invoke_host_function_op
invoke_host_function_op,
extra_fee_rate
) do
invoke_host_function_op = set_host_function_auth(invoke_host_function_op, auth, nil)
invoke_host_function_op = set_host_function_auth(invoke_host_function_op, auth, [])

{transaction_data, min_resource_fee} =
process_transaction_response(
Expand All @@ -195,7 +211,7 @@ defmodule Soroban.Contract.RPCCalls do
)

%BaseFee{fee: base_fee} = BaseFee.new()
fee = BaseFee.new(base_fee + min_resource_fee + round(min_resource_fee * 0.05))
fee = BaseFee.new(base_fee + min_resource_fee + round(min_resource_fee * extra_fee_rate))

{:ok, envelope_xdr} =
source_account
Expand All @@ -212,7 +228,8 @@ defmodule Soroban.Contract.RPCCalls do
{:ok, %SimulateTransactionResponse{}} = response,
_source_account,
_sequence_number,
_invoke_host_function_op
_invoke_host_function_op,
_extra_fee_rate
),
do: response

Expand All @@ -228,6 +245,13 @@ defmodule Soroban.Contract.RPCCalls do
),
do: invoke_host_function_op

defp set_host_function_auth(
%InvokeHostFunction{} = invoke_host_function_op,
auths,
[]
),
do: InvokeHostFunction.set_auth(invoke_host_function_op, auths)

defp set_host_function_auth(
%InvokeHostFunction{} = invoke_host_function_op,
auths,
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Soroban.MixProject do
use Mix.Project

@version "0.13.0"
@version "0.14.0"
@github_url "https://github.com/kommitters/soroban.ex"

def project do
Expand Down Expand Up @@ -43,7 +43,7 @@ defmodule Soroban.MixProject do
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.30", only: :dev, runtime: false},
{:excoveralls, "~> 0.16", only: :test},
{:excoveralls, "~> 0.17", only: :test},
{:stellar_sdk, "~> 0.17"},
{:hackney, "~> 1.18"}
]
Expand Down
Loading

0 comments on commit b141268

Please sign in to comment.