Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.17.0 #327

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
api.osv.dev:443
api.securityscorecards.dev:443
bestpractices.coreinfrastructure.org:443
fulcio.sigstore.dev:443
*.sigstore.dev:443
github.com:443
rekor.sigstore.dev:443
sigstore-tuf-root.storage.googleapis.com:443
oss-fuzz-build-logs.storage.googleapis.com:443

- name: "Checkout code"
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Changelog

## 0.16.0 (27.07.2023)
## 0.17.0 (04.08.2023)

* Finish Soroban Preview 10 Support:
* Support authorized invocation with different accounts.
* Support Upload Contract WASM.
* Support Create Contract.
* Support RestoreFootprint operation.
* Support BumpFootprintExpiration operation.

## 0.16.1 (27.07.2023)

* Update stellar base dependency.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The **Stellar SDK** is composed of two complementary components: **`TxBuild`** +
```elixir
def deps do
[
{:stellar_sdk, "~> 0.16.1"}
{:stellar_sdk, "~> 0.17.0"}
]
end
```
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
* [Upload Contract Code (WASM)](/docs/examples/soroban/upload_contract_code.md)
* [Create Contract](/docs/examples/soroban/create_contract.md)
* [Invoke Contract Function](/docs/examples/soroban/invoke_contract_functions.md)
* [Bump Footprint Expiration](/docs/examples/soroban/bump_footprint_expiration.md)
* [Restore Footprint](/docs/examples/soroban/restore_footprint.md)
97 changes: 97 additions & 0 deletions docs/examples/soroban/bump_footprint_expiration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Bump Footprint Expiration
The `BumpFootprintExpirationOp` operation is used to extend a contract data entry's lifetime.

A contract instance, wasm hash, and data storage entry (persistent/instance/temporary) can expire, so you can use this bump operation to extend its lifetime.
Read more about it:
- https://soroban.stellar.org/docs/fundamentals-and-concepts/state-expiration#bumpfootprintexpirationop
- https://docs.rs/soroban-sdk/latest/soroban_sdk/storage/struct.Storage.html

In this example, we will bump the contract instance of an already deployed contract in the network, adding 1000 ledgers to it.

> **Warning**
> Please note that Soroban is still under development, so breaking changes may occur.

> **Note**
> All this actions require to use `simulateTransaction` and `sendTransaction` RPC endpoints when specified in the code comments to achieve the bump footprint expiration.

```elixir
alias Stellar.TxBuild.{
Account,
BaseFee,
BumpFootprintExpiration,
LedgerKey,
SCAddress,
SCVal,
SequenceNumber,
Signature,
SorobanResources,
SorobanTransactionData
}

alias Stellar.KeyPair

contract_address = "CAMGSYINVVL6WP3Q5WPNL7FS4GZP37TWV7MKIRQF5QMYLK3N2SW4P3RC"
contract_sc_address = SCAddress.new(contract_address)
key = SCVal.new(ledger_key_contract_instance: nil)

keypair =
{public_key, _secret} =
Stellar.KeyPair.from_secret_seed("SCAVFA3PI3MJLTQNMXOUNBSEUOSY66YMG3T2KCQKLQBENNVLVKNPV3EK")

contract_data =
LedgerKey.new(
{:contract_data,
[
contract: contract_sc_address,
key: key,
durability: :persistent,
body_type: :data_entry
]}
)

hash= StellarBase.StrKey.decode!(contract_address, :contract)
contract_code = LedgerKey.new({:contract_code, [hash: hash, body_type: :data_entry]})
footprint = LedgerFootprint.new(read_only: [contract_data, contract_code])

soroban_data =
[
footprint: footprint,
instructions: 0,
read_bytes: 0,
write_bytes: 0,
extended_meta_data_size_bytes: 0
]
|> SorobanResources.new()
|> (&SorobanTransactionData.new(resources: &1, refundable_fee: 0)).()
|> SorobanTransactionData.to_xdr()

source_account = Account.new(public_key)
{:ok, seq_num} = Accounts.fetch_next_sequence_number(public_key)
sequence_number = SequenceNumber.new(seq_num)
signature = Signature.new(keypair)
bump_footprint_op = BumpFootprintExpiration.new(ledgers_to_expire: 1000)

# Use this XDR to simulate the transaction and get the soroban_data and min_resource_fee
source_account
|> Stellar.TxBuild.new(sequence_number: sequence_number)
|> Stellar.TxBuild.add_operation(bump_footprint_op)
|> Stellar.TxBuild.set_soroban_data(soroban_data)
|> Stellar.TxBuild.envelope()

# Simulate Transaction
soroban_data =
"AAAAAAAAAAIAAAAGAAAAARhpYQ2tV+s/cO2e1fyy4bL9/nav2KRGBewZhatt1K3HAAAAFAAAAAEAAAAAAAAABxhpYQ2tV+s/cO2e1fyy4bL9/nav2KRGBewZhatt1K3HAAAAAAAAAAAAAAAAAAABLAAAAAAAAAJYAAAAAAAAAHY="

min_resource_fee = 11_516
fee = BaseFee.new(min_resource_fee + 100)

# Use the XDR generated here to send it to the futurenet
source_account
|> Stellar.TxBuild.new(sequence_number: sequence_number)
|> Stellar.TxBuild.add_operation(bump_footprint_op)
|> Stellar.TxBuild.set_soroban_data(soroban_data)
|> Stellar.TxBuild.set_base_fee(fee)
|> Stellar.TxBuild.sign(signature)
|> Stellar.TxBuild.envelope()

```
62 changes: 39 additions & 23 deletions docs/examples/soroban/create_contract.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Create Contract

> **Warning**
> Please note that Soroban is still under development, so breaking changes may occur.

Expand All @@ -13,26 +14,36 @@ There are two types of contract creations:
alias Stellar.TxBuild.{
Account,
BaseFee,
InvokeHostFunction,
ContractExecutable,
ContractIDPreimage,
ContractIDPreimageFromAddress,
CreateContractArgs,
HostFunction,
HostFunctionArgs,
InvokeHostFunction,
SequenceNumber,
Signature
Signature,
SCAddress
}

alias Stellar.Horizon.Accounts

wasm_id = <<some binary here>>
wasm_ref = <<some binary here>>
address = SCAddress.new("GDEU46HFMHBHCSFA3K336I3MJSBZCWVI3LUGSNL6AF2BW2Q2XR7NNAPM")
salt = :crypto.strong_rand_bytes(32)

address_preimage = ContractIDPreimageFromAddress.new(address: address, salt: salt)
contract_id_preimage = ContractIDPreimage.new(from_address: address_preimage)
contract_executable = ContractExecutable.new(wasm_ref: wasm_ref)

function_args =
HostFunctionArgs.new(
type: :create,
wasm_id: wasm_id
create_contract_args =
CreateContractArgs.new(
contract_id_preimage: contract_id_preimage,
contract_executable: contract_executable
)

function = HostFunction.new(args: function_args)
host_function = HostFunction.new(create_contract: create_contract_args)

invoke_host_function_op = InvokeHostFunction.new(functions: [function])
invoke_host_function_op = InvokeHostFunction.new(host_function: host_function)

keypair =
{public_key, _secret} =
Expand All @@ -54,9 +65,9 @@ source_account

# Simulate Transaction
soroban_data =
"AAAAAQAAAAdw47HdjY6bhECndnofWxQ6D1mDQaYxvykdKi4f7bz4ygAAAAEAAAAGSCB+H17w48TbOf0PtCgDnGu0zOOzuVjMYSzmMYZOD0kAAAAUAAFCiwAAQ1QAAACAAAAAqAAAAAAAAAAhAAAAAA=="
"AAAAAAAAAAEAAAAHuoVwkiq7sFT5+6wPecWIC3zW3SXzDactjjMN9VUNzQIAAAAAAAAAAQAAAAYAAAABet+3VCiKSYoZDd/Ce32Dtp9tYwNFc64V/QfdZUJm4boAAAAUAAAAAQAAAAAAAX/UAAACyAAAAKQAAADYAAAAAAAAACs="

min_resource_fee = 54439
min_resource_fee = 38_733
fee = BaseFee.new(min_resource_fee + 100)

# Use the XDR generated here to send it to the futurenet
Expand All @@ -78,9 +89,11 @@ alias Stellar.TxBuild.{
Account,
Asset,
BaseFee,
InvokeHostFunction,
CreateContractArgs,
ContractIDPreimage,
ContractExecutable,
HostFunction,
HostFunctionArgs,
InvokeHostFunction,
SequenceNumber,
Signature
}
Expand All @@ -91,15 +104,18 @@ keypair = {public_key, _secret} = Stellar.KeyPair.from_secret_seed("SCA...3EK")

asset = Asset.new(code: :ABC, issuer: public_key)

function_args =
HostFunctionArgs.new(
type: :create,
asset: asset
contract_id_preimage = ContractIDPreimage.new(from_asset: asset)
contract_executable = ContractExecutable.new(:token)

create_contract_args =
CreateContractArgs.new(
contract_id_preimage: contract_id_preimage,
contract_executable: contract_executable
)

function = HostFunction.new(args: function_args)
host_function = HostFunction.new(create_contract: create_contract_args)

invoke_host_function_op = InvokeHostFunction.new(functions: [function])
invoke_host_function_op = InvokeHostFunction.new(host_function: host_function)

source_account = Account.new(public_key)

Expand All @@ -115,9 +131,9 @@ source_account
|> Stellar.TxBuild.envelope()

soroban_data =
"AAAAAAAAAAQAAAAGy7BJuM4i1Q0rEQ2fd0X9qJqvJugM2lEpbY21qRJAzmsAAAAPAAAACE1FVEFEQVRBAAAABsuwSbjOItUNKxENn3dF/aiaryboDNpRKW2NtakSQM5rAAAAEAAAAAEAAAABAAAADwAAAAVBZG1pbgAAAAAAAAbLsEm4ziLVDSsRDZ93Rf2omq8m6AzaUSltjbWpEkDOawAAABAAAAABAAAAAQAAAA8AAAAJQXNzZXRJbmZvAAAAAAAABsuwSbjOItUNKxENn3dF/aiaryboDNpRKW2NtakSQM5rAAAAFAAD2ZUAAADgAAADFAAAA/QAAAAAAAAAxgAAAAA="
"AAAAAAAAAAAAAAABAAAABgAAAAH3mbzcS3de+8X2xbTs9y5hcKA2c5Nvip1EIroM6x+eqAAAABQAAAABAAAAAAAEIzgAAAA0AAACGAAAA0gAAAAAAAAApQ=="

min_resource_fee = 12_7568
min_resource_fee = 36_155
fee = BaseFee.new(min_resource_fee + 100)

# Use the XDR generated here to send it to the futurenet
Expand All @@ -129,4 +145,4 @@ source_account
|> Stellar.TxBuild.sign(signature)
|> Stellar.TxBuild.envelope()

```
```
Loading