Skip to content
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: 3 additions & 1 deletion src/governor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
buildContractCallTx,
simulateReadOnly,
scValToI128,
scValToU32,
scValToU64,
NETWORK_PASSPHRASE,
DEFAULT_RPC,
Expand Down Expand Up @@ -65,8 +66,9 @@ function parseGovernorConfig(val: xdr.ScVal): GovernorConfig {
m[k] = e.val();
}
return {
feeBps: m['fee_bps']?.u32() ?? 0,
feeBps: m['fee_bps'] ? scValToU32(m['fee_bps']) : 0,
minDurationSeconds: m['min_duration_seconds'] ? Number(scValToU64(m['min_duration_seconds'])) : 0,
maxDurationSeconds: m['max_duration_seconds'] ? Number(scValToU64(m['max_duration_seconds'])) : 0,
maxRatePerSecond: m['max_rate_per_second'] ? scValToI128(m['max_rate_per_second']) : 0n,
// exactOptionalPropertyTypes forbids assigning `undefined` to an optional
// key directly — the key must be entirely absent instead, hence the
Expand Down
7 changes: 4 additions & 3 deletions src/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConduitError, UNKNOWN_CONTRACT_ERROR_CODE } from './errors.js';
import { IndexerTimeoutError, OperationAbortedError } from './errors.js';
import { bigintSafeStringify } from './utils.js';

export interface GraphQLQueryOptions {
query: string;
Expand Down Expand Up @@ -206,7 +207,7 @@ export class GraphQLIndexer {
fetchFn,
this.endpoint,
headers,
JSON.stringify(payload),
JSON.stringify({ ...payload, variables: bigintSafeStringify(payload.variables) }),
timeoutMs,
callerSignal,
);
Expand Down Expand Up @@ -407,7 +408,7 @@ export class GraphQLIndexer {
type: 'subscribe',
payload: {
query: options.query,
variables,
variables: bigintSafeStringify(variables),
},
});
} catch (err) {
Expand Down Expand Up @@ -493,7 +494,7 @@ export class GraphQLIndexer {
fetchFn(this.endpoint, {
method: 'POST',
headers,
body: JSON.stringify({ query: options.query, variables }),
body: JSON.stringify({ query: options.query, variables: bigintSafeStringify(variables) }),
signal: abortController.signal,
})
.then(async (response: Response) => {
Expand Down
2 changes: 1 addition & 1 deletion src/soroban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import {
SorobanRpc,

Check warning on line 9 in src/soroban.ts

View workflow job for this annotation

GitHub Actions / Lint & typecheck

'SorobanRpc' import from '@stellar/stellar-sdk' is restricted. SorobanRpc is deprecated in @stellar/stellar-sdk v12. Import rpc instead
TransactionBuilder,
Networks,
Contract,
Expand Down Expand Up @@ -305,7 +305,7 @@
const promise = (async () => {
const tx = await buildContractCallTx(rpcUrl, passphrase, callerAddr, tokenId, 'decimals', []);
const val = await simulateReadOnly(rpcUrl, passphrase, tx);
return val.u32();
return scValToU32(val);
})();

_tokenDecimalsCache.set(cacheKey, promise);
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface GovernorConfig {
feeBps: number;
feeRecipient?: string;
minDurationSeconds: number;
maxDurationSeconds: number;
maxRatePerSecond: bigint;
factoryAddress?: string;
}
Expand Down
8 changes: 5 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ export function toStroops(amount: string, decimals = 7): bigint {

/** Convert stroops (bigint) to a display amount string */
export function fromStroops(stroops: bigint, decimals = 7): string {
const neg = stroops < 0n;
const abs = neg ? -stroops : stroops;
const factor = pow10(decimals);
const whole = stroops / factor;
const rem = stroops % factor;
const whole = abs / factor;
const rem = abs % factor;
const frac = rem.toString().padStart(decimals, '0');
let end = frac.length;
while (end > 1 && frac.charCodeAt(end - 1) === 48) {
end--;
}
const trimmed = frac.slice(0, end);
return `${whole}.${trimmed}`;
return `${neg ? '-' : ''}${whole}.${trimmed}`;
}

/**
Expand Down
Loading