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/5.5.0 #952

Merged
merged 50 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
197b62c
adds the bump footprint expiration op type to tx history
aristidesstaffieri Aug 15, 2023
22128cf
WIP, refactors history item to build async rows
aristidesstaffieri Aug 15, 2023
bf0ae88
clean up and organize soroban related helpers
aristidesstaffieri Aug 16, 2023
12e79ce
Added translations
aristidesstaffieri Aug 16, 2023
2dd3ba2
remove unwanted files from translations commit
aristidesstaffieri Aug 16, 2023
3a30f47
removes helper shim and fixes import pattern
aristidesstaffieri Aug 18, 2023
5a801ad
use sdk base fee, add restore footprint header title, use more direct…
aristidesstaffieri Aug 18, 2023
a617560
fixes soroban tx submission error handling, bumps soroban-client
aristidesstaffieri Aug 18, 2023
5ab3fb6
fix use of source account in SorobanContext newTxBuilder
aristidesstaffieri Aug 18, 2023
1a2a669
split transfer and mint history items
aristidesstaffieri Aug 18, 2023
e756283
Added translations
aristidesstaffieri Aug 18, 2023
1c87214
WIP, adds base states for testing soroban token payment
aristidesstaffieri Aug 18, 2023
588385d
adds mock soroban context, tests token payment flow
aristidesstaffieri Aug 21, 2023
a27fd26
adds tests for soroban helpers
aristidesstaffieri Aug 21, 2023
01b4947
adds token amount dom test
aristidesstaffieri Aug 21, 2023
e4cce93
adds new path for signing auth entries, adds SignAuthEntry component …
aristidesstaffieri Aug 21, 2023
bf89d72
Adds basic signing component for auth entry sign flow
aristidesstaffieri Aug 22, 2023
e5b6f46
Adds new external api signAuthEntry, adds docs, adds sign auth entry …
aristidesstaffieri Aug 22, 2023
74c84a8
Added translations
aristidesstaffieri Aug 22, 2023
5d821f1
adds buildInvocationTree to render formatted json for invocations and…
aristidesstaffieri Aug 23, 2023
ad4c654
use correct key in responseQueue handler for signAuthEntry, clean up …
aristidesstaffieri Aug 23, 2023
4752cea
splits SignTx and SignBlob, makes new route for sign-blob
aristidesstaffieri Aug 23, 2023
0cdba8b
use buildInvocationTree in transaction render for signTx
aristidesstaffieri Aug 24, 2023
21eda37
Added translations
aristidesstaffieri Aug 24, 2023
3b41c73
Added translations
aristidesstaffieri Aug 24, 2023
ed7268f
remove accidental tarball commit
aristidesstaffieri Aug 24, 2023
c50935b
adds missing loading states, fixes missing error handling in message …
aristidesstaffieri Aug 24, 2023
1ce4372
remove extra line
aristidesstaffieri Aug 24, 2023
5586f0f
refactors signing flows to use a common helper hook
aristidesstaffieri Aug 25, 2023
5242f07
dont allow HW signing on sign blob or sign auth entry, not currently …
aristidesstaffieri Aug 25, 2023
e3181bb
Added translations
aristidesstaffieri Aug 25, 2023
6cc27d9
Added translations
aristidesstaffieri Aug 25, 2023
db667a7
updates HW wallet not supported text
aristidesstaffieri Aug 25, 2023
90a4b21
Added translations
aristidesstaffieri Aug 25, 2023
d6508d2
refactors SorobanContext to accoutn for missing rpc urls
aristidesstaffieri Aug 28, 2023
15d138e
moves dispatch to be in shared signing hook
aristidesstaffieri Aug 28, 2023
504f274
Merge remote-tracking branch 'origin' into release/5.5.0
aristidesstaffieri Sep 7, 2023
b939723
Merge branch 'master' into release/5.5.0
piyalbasu Sep 13, 2023
0068f89
Merge commit 'c5003b0766a5434075031508b81db4feb48f1166' into release/…
piyalbasu Sep 13, 2023
d5b0ef6
add translations
piyalbasu Sep 13, 2023
c59378d
Release/5.6.0 (#954)
piyalbasu Sep 13, 2023
47d7216
Refactor/multi network custom token (#958)
aristidesstaffieri Sep 14, 2023
0b7b3e3
add prettier changes
piyalbasu Sep 14, 2023
81fe24f
Added translations
piyalbasu Sep 14, 2023
f3153db
Merge branch 'master' into release/5.5.0
piyalbasu Sep 14, 2023
f866117
WIP: upgrade soroban-client (#961)
piyalbasu Sep 16, 2023
41fcde9
move schema update
piyalbasu Sep 16, 2023
7853b29
fix migration key
piyalbasu Sep 16, 2023
197e06d
rm log
piyalbasu Sep 16, 2023
2f4d161
fix account history
piyalbasu Sep 16, 2023
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
28 changes: 28 additions & 0 deletions @shared/api/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const submitTransaction = async (
});
} catch (e) {
console.error(e);
throw e;
}
const { signedTransaction, error } = response;

Expand All @@ -86,6 +87,7 @@ export const submitBlob = async (
});
} catch (e) {
console.error(e);
throw e;
}
const { signedBlob, error } = response;

Expand All @@ -95,6 +97,32 @@ export const submitBlob = async (
return signedBlob;
};

export const submitAuthEntry = async (
entryXdr: string,
opts?: {
accountToSign?: string;
},
): Promise<string> => {
let response = { signedAuthEntry: "", error: "" };
const _opts = opts || {};
const accountToSign = _opts.accountToSign || "";
try {
response = await sendMessageToContentScript({
entryXdr,
accountToSign,
type: EXTERNAL_SERVICE_TYPES.SUBMIT_AUTH_ENTRY,
});
} catch (e) {
console.error(e);
}
const { signedAuthEntry, error } = response;

if (error) {
throw error;
}
return signedAuthEntry;
};

export const requestNetwork = async (): Promise<string> => {
let response = { network: "", error: "" };
try {
Expand Down
4 changes: 0 additions & 4 deletions @shared/api/helpers/soroban.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { xdr, Address, ScInt, scValToBigInt } from "soroban-client";

/* eslint-disable */

export const accountIdentifier = (account: string) =>
new Address(account).toScVal();

Expand All @@ -27,5 +25,3 @@ export const decodeU32 = (b64: string) =>

export const numberToI128 = (value: number): xdr.ScVal =>
new ScInt(value).toI128();

/* eslint-enable */
186 changes: 93 additions & 93 deletions @shared/api/internal.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import StellarSdk from "stellar-sdk";
import * as SorobanClient from "soroban-client";
import { DataProvider } from "@stellar/wallet-sdk";
import {
getBalance,
getDecimals,
getName,
getSymbol,
} from "@shared/helpers/soroban/token";
import {
Account,
AccountBalancesInterface,
AccountHistoryInterface,
Balances,
HorizonOperation,
Settings,
SorobanTxStatus,
} from "./types";
import {
MAINNET_NETWORK_DETAILS,
DEFAULT_NETWORKS,
NetworkDetails,
NETWORKS,
SOROBAN_RPC_URLS,
} from "../constants/stellar";
import { SERVICE_TYPES } from "../constants/services";
Expand All @@ -24,10 +30,25 @@ import { getIconUrlFromIssuer } from "./helpers/getIconUrlFromIssuer";
import { getDomainFromIssuer } from "./helpers/getDomainFromIssuer";
import { stellarSdkServer } from "./helpers/stellarSdkServer";

import { decodei128, decodeU32, decodeStr } from "./helpers/soroban";

const TRANSACTIONS_LIMIT = 100;

export const SendTxStatus: {
[index: string]: SorobanClient.SorobanRpc.SendTransactionStatus;
} = {
Pending: "PENDING",
Duplicate: "DUPLICATE",
Retry: "TRY_AGAIN_LATER",
Error: "ERROR",
};

export const GetTxStatus: {
[index: string]: SorobanClient.SorobanRpc.GetTransactionStatus;
} = {
Success: SorobanClient.SorobanRpc.GetTransactionStatus.SUCCESS,
NotFound: SorobanClient.SorobanRpc.GetTransactionStatus.NOT_FOUND,
Failed: SorobanClient.SorobanRpc.GetTransactionStatus.FAILED,
};

export const createAccount = async (
password: string,
): Promise<{ publicKey: string; allAccounts: Array<Account> }> => {
Expand Down Expand Up @@ -515,6 +536,16 @@ export const signBlob = async (): Promise<void> => {
}
};

export const signAuthEntry = async (): Promise<void> => {
try {
await sendMessageToBackground({
type: SERVICE_TYPES.SIGN_AUTH_ENTRY,
});
} catch (e) {
console.error(e);
}
};

export const signFreighterTransaction = async ({
transactionXDR,
network,
Expand Down Expand Up @@ -606,28 +637,49 @@ export const submitFreighterSorobanTransaction = async ({
console.error(e);
}

const server = new SorobanClient.Server(SOROBAN_RPC_URLS.FUTURENET, {
allowHttp: true,
if (
!networkDetails.sorobanRpcUrl &&
networkDetails.network !== NETWORKS.FUTURENET
) {
throw new Error("soroban rpc not supported");
}

// TODO: after enough time has passed to assume most clients have ran
// the migrateSorobanRpcUrlNetworkDetails migration, remove and use networkDetails.sorobanRpcUrl
const serverUrl = !networkDetails.sorobanRpcUrl
? SOROBAN_RPC_URLS[NETWORKS.FUTURENET]!
: networkDetails.sorobanRpcUrl;

const server = new SorobanClient.Server(serverUrl, {
allowHttp: !serverUrl.startsWith("https"),
});

// TODO: fixed in Sorobanclient, not yet released
let response = (await server.sendTransaction(tx)) as any;
let response = await server.sendTransaction(tx);

try {
// Poll this until the status is not "pending"
while (response.status === SorobanTxStatus.PENDING) {
if (response.errorResultXdr) {
throw new Error(response.errorResultXdr);
}

if (response.status === SendTxStatus.Pending) {
let txResponse = await server.getTransaction(response.hash);

// Poll this until the status is not "NOT_FOUND"
while (txResponse.status === GetTxStatus.NotFound) {
// See if the transaction is complete
// eslint-disable-next-line no-await-in-loop
response = await server.getTransaction(response.id);
txResponse = await server.getTransaction(response.hash);
// Wait a second
// eslint-disable-next-line no-await-in-loop
await new Promise((resolve) => setTimeout(resolve, 1000));
}
} catch (e) {
throw new Error(e);
}

return response;
return response;
// eslint-disable-next-line no-else-return
} else {
throw new Error(
`Unabled to submit transaction, status: ${response.status}`,
);
}
};

export const addRecentAddress = async ({
Expand Down Expand Up @@ -859,98 +911,42 @@ export const getBlockedAccounts = async () => {
return resp;
};

type TxToOp = {
[index: string]: {
tx: SorobanClient.Transaction<
SorobanClient.Memo<SorobanClient.MemoType>,
SorobanClient.Operation[]
>;
decoder: (xdr: string) => string | number;
};
};

interface SorobanTokenRecord {
[key: string]: unknown;
balance: number;
name: string;
symbol: string;
decimals: string;
}

export const getSorobanTokenBalance = (
export const getSorobanTokenBalance = async (
server: SorobanClient.Server,
contractId: string,
txBuilders: {
// need a builder per operation until multi-op transactions are released
// need a builder per operation, Soroban currently has single op transactions
balance: SorobanClient.TransactionBuilder;
name: SorobanClient.TransactionBuilder;
decimals: SorobanClient.TransactionBuilder;
symbol: SorobanClient.TransactionBuilder;
},
params: SorobanClient.xdr.ScVal[],
balanceParams: SorobanClient.xdr.ScVal[],
) => {
const contract = new SorobanClient.Contract(contractId);

// Right now we can only have 1 operation per TX in Soroban
// There is ongoing work to lift this restriction
// but for now we need to do 4 txs to show 1 user balance. :(
const balanceTx = txBuilders.balance
.addOperation(contract.call("balance", ...params))
.setTimeout(SorobanClient.TimeoutInfinite)
.build();

const nameTx = txBuilders.name
.addOperation(contract.call("name"))
.setTimeout(SorobanClient.TimeoutInfinite)
.build();

const symbolTx = txBuilders.symbol
.addOperation(contract.call("symbol"))
.setTimeout(SorobanClient.TimeoutInfinite)
.build();

const decimalsTx = txBuilders.decimals
.addOperation(contract.call("decimals"))
.setTimeout(SorobanClient.TimeoutInfinite)
.build();

const txs: TxToOp = {
balance: {
tx: balanceTx,
decoder: decodei128,
},
name: {
tx: nameTx,
decoder: decodeStr,
},
symbol: {
tx: symbolTx,
decoder: decodeStr,
},
decimals: {
tx: decimalsTx,
decoder: decodeU32,
},
};

const tokenBalanceInfo = Object.keys(txs).reduce(async (prev, curr) => {
const _prev = await prev;
const { tx, decoder } = txs[curr];
const { results } = await server.simulateTransaction(tx);
if (!results || results.length !== 1) {
throw new Error("Invalid response from simulateTransaction");
}
const result = results[0];
_prev[curr] = decoder(result.xdr);

return _prev;
}, Promise.resolve({} as SorobanTokenRecord));
// for now we need to do 4 tx simulations to show 1 user balance. :(
// TODO: figure out how to fetch ledger keys to do this more efficiently
const decimals = await getDecimals(contractId, server, txBuilders.decimals);
const name = await getName(contractId, server, txBuilders.name);
const symbol = await getSymbol(contractId, server, txBuilders.symbol);
const balance = await getBalance(
contractId,
balanceParams,
server,
txBuilders.balance,
);

return tokenBalanceInfo;
return {
balance,
decimals,
name,
symbol,
};
};

export const addTokenId = async (
tokenId: string,
network: SorobanClient.Networks,
): Promise<{
tokenIdList: string[];
}> => {
Expand All @@ -960,6 +956,7 @@ export const addTokenId = async (
try {
({ tokenIdList, error } = await sendMessageToBackground({
tokenId,
network,
type: SERVICE_TYPES.ADD_TOKEN_ID,
}));
} catch (e) {
Expand All @@ -973,9 +970,12 @@ export const addTokenId = async (
return { tokenIdList };
};

export const getTokenIds = async (): Promise<string[]> => {
export const getTokenIds = async (
network: SorobanClient.Networks,
): Promise<string[]> => {
const resp = await sendMessageToBackground({
type: SERVICE_TYPES.GET_TOKEN_IDS,
network,
});
return resp.tokenIdList;
};
2 changes: 1 addition & 1 deletion @shared/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@stellar/wallet-sdk": "^0.8.0",
"bignumber.js": "^9.1.1",
"prettier": "^2.0.5",
"soroban-client": "^0.9.1",
"soroban-client": "^1.0.0-beta.2",
"stellar-sdk": "^10.4.1",
"typescript": "~3.7.2",
"webextension-polyfill": "^0.10.0"
Expand Down
Loading
Loading