Skip to content

Commit 1bf87d2

Browse files
committed
Refactor to allow multiple versions of the router contract, update the stellar sdk to latest
1 parent f4da55f commit 1bf87d2

File tree

6 files changed

+260
-74
lines changed

6 files changed

+260
-74
lines changed

README.md

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@ npx jsr add @creit-tech/stellar-assets-sdk
1616

1717
You can check more installation methods (deno, pnpm, etc) from [here](https://jsr.io/@creit-tech/stellar-router-sdk/)
1818

19+
## Choose your contract to use
20+
21+
The first thing to take in consideration is the nature of these "Meta Contracts": they are simple immutable contracts,
22+
so every time we add new features they will be in a separated contract. This allows you to use the one that fits your
23+
use case and if for example the only thing you need to do is making an atomic call then using the V0 is the best choice.
24+
25+
If you want to use the contract V0 then you will use the `InvocationV0` class, while if you want to use the V1 then you
26+
will use the `InvocationV1`. You can check the current versions available and what they do
27+
[here](https://github.com/Creit-Tech/Stellar-Router-Contract).
28+
1929
## How to use
2030

21-
Because the library it's pretty simple, using is also simple. Here is an example of us fetching a list of 19 balances
22-
from different contracts calls at once.
31+
Because the library it's pretty simple, using it is also simple. Here is an example of us fetching a list of 19 balances
32+
from different contracts calls at once (BUT, if you need to fetch balances like this, we suggest you using our
33+
[Stellar Assets SDK](https://jsr.io/@creit-tech/stellar-assets-sdk) because it takes more stuff in consideration).
2334

2435
```typescript
25-
import { StellarRouterSdk } from "@creit-tech/stellar-router-sdk";
36+
import { InvocationV0, StellarRouterSdk } from "@creit-tech/stellar-router-sdk";
2637

2738
const assets: string[] = [
2839
"CAUIKL3IYGMERDRUN6YSCLWVAKIFG5Q4YJHUKM4S4NJZQIA3BAS6OJPK",
@@ -48,11 +59,13 @@ const assets: string[] = [
4859

4960
const sdk: StellarRouterSdk = new StellarRouterSdk({ rpcUrl: "https://mainnet.sorobanrpc.com" });
5061
const xbullSwapContract: string = "CB3JAPDEIMA3OOSALUHLYRGM2QTXGVD3EASALPFMVEU2POLLULJBT2XN";
51-
const invocations: Invocation[] = assets.map((contract: string): Invocation => ({
52-
contract,
53-
method: "balance",
54-
args: [new Address(xbullSwapContract).toScVal()],
55-
}));
62+
const invocations: InvocationV0[] = assets.map((contract: string): InvocationV0 =>
63+
new InvocationV0({
64+
contract,
65+
method: "balance",
66+
args: [new Address(xbullSwapContract).toScVal()],
67+
})
68+
);
5669

5770
const balances: bigint[] = await sdk.simResult(invocations);
5871
```
@@ -63,7 +76,7 @@ directly supporting it).
6376

6477
```typescript
6578
import { SorobanDomainsSDK } from "@creit-tech/sorobandomains-sdk";
66-
import { StellarRouterSdk } from "@creit-tech/stellar-router-sdk";
79+
import { InvocationV0, StellarRouterSdk } from "@creit-tech/stellar-router-sdk";
6780
import { xdr } from "@stellar/stellar-sdk";
6881

6982
const routerSdk = new StellarRouterSdk();
@@ -76,21 +89,26 @@ const { value } = await domainsSdk.searchDomain({ domain });
7689

7790
const contractCall: xdr.Operation<Operation.InvokeHostFunction> = routerSdk.exec(
7891
domainOwner,
79-
[{
80-
contract: domainsContract,
81-
method: "burn_record",
82-
args: [xdr.ScVal.scvVec([xdr.ScVal.scvSymbol("Record"), xdr.ScVal.scvBytes(new TextEncoder().encode(value.node))])],
83-
}, {
84-
contract: domainsContract,
85-
method: "set_record",
86-
args: [
87-
nativeToScVal(new TextEncoder().encode(domain), { type: "bytes" }),
88-
nativeToScVal(new TextEncoder().encode("xlm"), { type: "bytes" }),
89-
nativeToScVal(value.address, { type: "address" }),
90-
nativeToScVal(value.address, { type: "address" }),
91-
nativeToScVal(3600n * 24n * 365n * 5n, { type: "u64" }),
92-
],
93-
}],
92+
[
93+
new InvocationV0({
94+
contract: domainsContract,
95+
method: "burn_record",
96+
args: [
97+
xdr.ScVal.scvVec([xdr.ScVal.scvSymbol("Record"), xdr.ScVal.scvBytes(new TextEncoder().encode(value.node))]),
98+
],
99+
}),
100+
new InvocationV0({
101+
contract: domainsContract,
102+
method: "set_record",
103+
args: [
104+
nativeToScVal(new TextEncoder().encode(domain), { type: "bytes" }),
105+
nativeToScVal(new TextEncoder().encode("xlm"), { type: "bytes" }),
106+
nativeToScVal(value.address, { type: "address" }),
107+
nativeToScVal(value.address, { type: "address" }),
108+
nativeToScVal(3600n * 24n * 365n * 5n, { type: "u64" }),
109+
],
110+
}),
111+
],
94112
);
95113

96114
// Now you build the transaction, add the operation from above and send it to the network.

deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@creit-tech/stellar-router-sdk",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"license": "MIT",
55
"exports": "./src/mod.ts",
66
"fmt": {
77
"lineWidth": 120
88
},
99
"imports": {
1010
"@std/assert": "jsr:@std/assert@1",
11-
"@stellar/stellar-sdk": "npm:@stellar/stellar-sdk@^13.2.0"
11+
"@stellar/stellar-sdk": "npm:@stellar/stellar-sdk@^14.1.1"
1212
}
1313
}

0 commit comments

Comments
 (0)