Skip to content

Instantly share code, notes, and snippets.

@Rexagon
Created September 1, 2023 13:14
Show Gist options
  • Save Rexagon/904b20102d4c12b112df29e57b89fef4 to your computer and use it in GitHub Desktop.
Save Rexagon/904b20102d4c12b112df29e57b89fef4 to your computer and use it in GitHub Desktop.
Get config params
import { Address, ProviderRpcClient } from "everscale-inpage-provider";
import { EverscaleStandaloneClient } from "everscale-standalone-client/nodejs";
const ever = new ProviderRpcClient({
forceUseFallback: true,
fallback: () =>
EverscaleStandaloneClient.create({
connection: {
id: 123,
type: "proto",
data: {
endpoint: "https://jrpc.everwallet.net",
},
},
}),
});
const start = async () => {
await ever.ensureInitialized();
const config = new ever.Contract(
CONFIG_ABI,
new Address(
"-1:5555555555555555555555555555555555555555555555555555555555555555"
)
);
const { fields } = await config.getFields({ allowPartial: true });
if (fields == null) {
throw new Error("Config contract state not found");
}
const { boc: nonEmptyMap } = await ever.packIntoCell({
abiVersion: "2.2",
structure: [
{ name: "flag", type: "bool" },
{ name: "root", type: "cell" },
] as const,
data: {
flag: true,
root: fields.paramsRoot,
},
});
const {
data: { params: rawParams },
} = await ever.unpackFromCell({
abiVersion: "2.2",
structure: [{ name: "params", type: "map(uint32,cell)" }] as const,
allowPartial: true,
boc: nonEmptyMap,
});
const params = new Map<number, string>();
for (const [id, value] of rawParams) {
params.set(parseInt(id), value);
}
const {
data: { value: mcPrices },
} = await ever.unpackFromCell({
abiVersion: "2.2",
structure: PRICES_PARAM_ABI,
allowPartial: true,
boc: params.get(20)!,
});
const {
data: { value: scPrices },
} = await ever.unpackFromCell({
abiVersion: "2.2",
structure: PRICES_PARAM_ABI,
allowPartial: true,
boc: params.get(21)!,
});
console.log(scPrices);
/*{
tag1: '209',
gasPrice: '1000',
gasLimit: '1000000',
tag2: '222',
specialGasLimit: '65536000',
gasCredit: '1000000',
blockGasLimit: '1000000',
freezeDueLimit: '10000',
deleteDueLimit: '10000000',
flatGasLimit: '100000000',
flatGasPrice: '1000000000'
}*/
};
start().catch(console.error);
const CONFIG_ABI = {
"ABI version": 2,
version: "2.2",
header: [],
functions: [],
events: [],
fields: [
{
name: "paramsRoot",
type: "cell",
},
],
} as const;
const PRICES_PARAM_ABI = [
{
name: "value",
type: "tuple",
components: [
// Flat tag
{ name: "tag1", type: "uint8" },
// The price of gas unit.
{ name: "gasPrice", type: "uint64" },
// The maximum amount of gas available for a compute phase of an ordinary transaction.
{ name: "gasLimit", type: "uint64" },
// Ext tag
{ name: "tag2", type: "uint8" },
// The maximum amount of gas available for a compute phase of a special transaction.
{ name: "specialGasLimit", type: "uint64" },
// The maximum amount of gas available before `ACCEPT`.
{ name: "gasCredit", type: "uint64" },
// The maximum amount of gas units per block.
{ name: "blockGasLimit", type: "uint64" },
// Amount of debt (in tokens) after which the account will be frozen.
{ name: "freezeDueLimit", type: "uint64" },
// Amount of debt (in tokens) after which the contract will be deleted.
{ name: "deleteDueLimit", type: "uint64" },
// Size of the first portion of gas with different price.
{ name: "flatGasLimit", type: "uint64" },
// The gas price for the first portion determinted by flatGasLimit
{ name: "flatGasPrice", type: "uint64" },
],
},
] as const;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment