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

Sdk 4249 do not hide exit code in flex sdk #48

Merged
merged 3 commits into from
Feb 10, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.secret/
/playwright-report/
/dist/
/integration-test/test-results/
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
All notable changes to this project will be documented in this file.


## [0.11.0] – 2022-12-14

### New

- all functions with the userId/traderId as an input now accepts:
1) hex string with `0x` prefix;
2) hex string of 64 char length without `0x` prefix;
3) decimal string.

- `Trader.deployEverWallet` accepts token parameters as `TokenValue` instead of `number`'s.

- Changed contract errors: "<contract-name> failed with exit code <exit-code>. <known-contract-error-message>.".

## [0.10.2] – 2022-12-14

### Fixed
Expand Down
12 changes: 5 additions & 7 deletions contracts/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export function errorFromExitCode(contract: AccountClass, exitCode: number): Con
exitCode < 0 ? `_cpp_${Math.abs(exitCode)}` : exitCode.toString()
}`,
exitCode,
message: `${contract.name} failed with exit code ${exitCode}. See contract documentation or contact contract developers for details.`,
message: `See contract documentation or contact contract developers for details.`,
};
const error: ContractError = new Error(contractError.message);
const error: ContractError = new Error(
`${contract.name} failed with exit code ${exitCode}. ${contractError.message}.`,
);
error.code = ProcessingErrorCode.MessageRejected;
error.data = {
...error.data,
Expand Down Expand Up @@ -59,11 +61,7 @@ export function findTransactionError(
contract: AccountClass,
altErrorCode: number = 0,
): Error | undefined {
const {
id,
aborted,
account_addr,
} = transaction;
const { id, aborted, account_addr } = transaction;
const exitCode = transaction.compute?.exit_code ?? 0;
const errorCode = exitCode !== 0 ? exitCode : altErrorCode;
if (!aborted && errorCode === 0) {
Expand Down
14 changes: 5 additions & 9 deletions examples/delegate-evers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Flex, Trader } from "../flex";
import { CONFIG, EXAMPLES_FLEX_CONFIG } from "./examples";


(async () => {
const flex = new Flex(EXAMPLES_FLEX_CONFIG);
try {
Expand All @@ -14,20 +13,17 @@ import { CONFIG, EXAMPLES_FLEX_CONFIG } from "./examples";
tokens: 100,
evers: 20,
keepEvers: 15,
traderId: traderId,
traderId,
...CONFIG.tip3.EVER,
});

flex.evr.log.info("Trader EVER wallet address:", trader_ever_wallet, "has been topped-up.");
flex.evr.log.info(
"Trader balances:",
await Trader.queryWallets(
flex,
{
clientAddress: clientAddress,
traderId: traderId,
},
),
await Trader.queryWallets(flex, {
clientAddress: clientAddress,
traderId,
}),
);

await flex.close();
Expand Down
4 changes: 2 additions & 2 deletions examples/delegate-tip3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CONFIG, EXAMPLES_FLEX_CONFIG } from "./examples";
let trader_tip3_wallet = await Trader.deployTip31Wallet(flex, {
clientAddress: clientAddress,
everWallet: CONFIG.everWallet,
traderId: traderId,
traderId,
tokenUnits: "10000000000",
transferEvers: 21,
evers: 20,
Expand All @@ -27,7 +27,7 @@ import { CONFIG, EXAMPLES_FLEX_CONFIG } from "./examples";
flex,
{
clientAddress: clientAddress,
traderId: traderId,
traderId,
},
),
);
Expand Down
6 changes: 3 additions & 3 deletions flex/client/deploy-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flex } from "../flex";
import { AccountOptionsEx, UserDataConfigAccount } from "../../contracts";
import { EverWallet, SignerOption, toUnits } from "../web3";
import { EverWallet, SignerOption, toUnitsBigIntString } from "../web3";

export type DeployClientOptions = {
/**
Expand Down Expand Up @@ -48,13 +48,13 @@ export async function deployClient(flex: Flex, options: DeployClientOptions): Pr
const everWallet = new EverWallet(flex.evr, options.everWallet);
await everWallet.transfer({
dest: await userConfig.getAddress(),
value: toUnits(transferEvers),
value: toUnitsBigIntString(transferEvers),
payload: {
abi: UserDataConfigAccount.package.abi,
fn: "deployFlexClient",
params: {
pubkey,
deploy_evers: toUnits(deployEvers),
deploy_evers: toUnitsBigIntString(deployEvers),
signature,
},
},
Expand Down
34 changes: 17 additions & 17 deletions flex/exchange/deploy-exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "../../contracts/generated/SuperRootOwnerAccount";
import { addEverTokenType, EverTokenTypeOptions, TokenTypeInfo } from "./ever-token-type";
import { addTip3TokenType, Tip3TokenTypeOptions } from "./tip3-token-type";
import { EverWallet, SignerOption, toUnits, Evr } from "../web3";
import { EverWallet, SignerOption, toUnitsBigIntString, Evr } from "../web3";

export type DeployExchangeOptions = {
everWallet: AccountOptionsEx;
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function deployExchange(
if (!superRootAddress || !(await web3.accounts.isActive(superRootAddress))) {
superRootAddress = (
await superRootOwner.runDeploySuperRoot({
evers: toUnits(options.superRootEvers ?? DEFAULTS.superRootEvers),
evers: toUnitsBigIntString(options.superRootEvers ?? DEFAULTS.superRootEvers),
prev_super_root: options.prevSuperRoot,
})
).output.value0;
Expand Down Expand Up @@ -210,9 +210,9 @@ function wrappersConfig(
const options = exchangeOptions.wrappers;
const defaults = DEFAULTS.wrappers;
return {
main_evers: toUnits(options?.mainEvers ?? defaults.mainEvers),
deploy_evers: toUnits(options?.deployEvers ?? defaults.deployEvers),
wrappers_cfg_keep_evers: toUnits(options?.keepEvers ?? defaults.keepEvers),
main_evers: toUnitsBigIntString(options?.mainEvers ?? defaults.mainEvers),
deploy_evers: toUnitsBigIntString(options?.deployEvers ?? defaults.deployEvers),
wrappers_cfg_keep_evers: toUnitsBigIntString(options?.keepEvers ?? defaults.keepEvers),
token_version: options?.version ?? exchangeOptions.version?.wallet ?? 1,
};
}
Expand All @@ -221,25 +221,25 @@ function flexConfig(exchangeOptions: DeployExchangeOptions): SuperRootOwnerDeplo
const options = exchangeOptions.flex;
const defaults = DEFAULTS.flex;
return {
main_evers: toUnits(options?.mainEvers ?? defaults.mainEvers),
deploy_evers: toUnits(options?.deployEvers ?? defaults.deployEvers),
keep_evers: toUnits(options?.keepEvers ?? defaults.keepEvers),
main_evers: toUnitsBigIntString(options?.mainEvers ?? defaults.mainEvers),
deploy_evers: toUnitsBigIntString(options?.deployEvers ?? defaults.deployEvers),
keep_evers: toUnitsBigIntString(options?.keepEvers ?? defaults.keepEvers),
evers: {
deploy: toUnits(options?.evers?.deploy ?? defaults.evers.deploy),
setnext: toUnits(options?.evers?.setNext ?? defaults.evers.setNext),
pair_keep: toUnits(options?.evers?.pairKeep ?? defaults.evers.pairKeep),
deploy: toUnitsBigIntString(options?.evers?.deploy ?? defaults.evers.deploy),
setnext: toUnitsBigIntString(options?.evers?.setNext ?? defaults.evers.setNext),
pair_keep: toUnitsBigIntString(options?.evers?.pairKeep ?? defaults.evers.pairKeep),
},
old_flex: options?.oldFlex,
exchange_version: options?.version ?? exchangeOptions.version?.exchange ?? 1,
ev_cfg: {
transfer_tip3: toUnits(options?.fees?.transferTip3 ?? defaults.fees.transferTip3),
return_ownership: toUnits(
transfer_tip3: toUnitsBigIntString(options?.fees?.transferTip3 ?? defaults.fees.transferTip3),
return_ownership: toUnitsBigIntString(
options?.fees?.returnOwnership ?? defaults.fees.returnOwnership,
),
order_answer: toUnits(options?.fees?.orderAnswer ?? defaults.fees.orderAnswer),
process_queue: toUnits(options?.fees?.processQueue ?? defaults.fees.processQueue),
send_notify: toUnits(options?.fees?.sendNotify ?? defaults.fees.sendNotify),
dest_wallet_keep_evers: toUnits(
order_answer: toUnitsBigIntString(options?.fees?.orderAnswer ?? defaults.fees.orderAnswer),
process_queue: toUnitsBigIntString(options?.fees?.processQueue ?? defaults.fees.processQueue),
send_notify: toUnitsBigIntString(options?.fees?.sendNotify ?? defaults.fees.sendNotify),
dest_wallet_keep_evers: toUnitsBigIntString(
options?.fees?.destWalletKeepEvers ?? defaults.fees.destWalletKeepEvers,
),
},
Expand Down
12 changes: 6 additions & 6 deletions flex/exchange/ever-token-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
WrapperEverAccount,
AccountOptionsEx,
} from "../../contracts";
import { EverWallet, toUnits, Evr, SignerOption } from "../web3";
import { EverWallet, toUnitsBigIntString, Evr, SignerOption } from "../web3";

export const EVER_TOKEN_TYPE = 1;

Expand Down Expand Up @@ -64,9 +64,9 @@ export async function addEverTokenType(
pubkey: `0x${deployerPublicKey}`,
wrapper_pubkey: `0x${wrapperPublicKey}`,
super_root: options.superRoot,
wrapper_deploy_value: toUnits(options.wrapperDeployEvers ?? DEFAULTS.wrapperDeployEvers),
wrapper_keep_balance: toUnits(options.wrapperKeepEvers ?? DEFAULTS.wrapperKeepEvers),
reserve_wallet_value: toUnits(options.reserveWalletEvers ?? DEFAULTS.reserveWalletEvers),
wrapper_deploy_value: toUnitsBigIntString(options.wrapperDeployEvers ?? DEFAULTS.wrapperDeployEvers),
wrapper_keep_balance: toUnitsBigIntString(options.wrapperKeepEvers ?? DEFAULTS.wrapperKeepEvers),
reserve_wallet_value: toUnitsBigIntString(options.reserveWalletEvers ?? DEFAULTS.reserveWalletEvers),
});
await deployer.runSetWrapperEverCode({ code: WrapperEverAccount.package.code });
// await deployer.runSetExtWalletCode({ code: TONTokenWalletAccount.package.code });
Expand All @@ -75,8 +75,8 @@ export async function addEverTokenType(
const superRootOwner = await web3.accounts.get(SuperRootOwnerAccount, options.superRootOwner);
await superRootOwner.runAddWrapperType({
type: EVER_TOKEN_TYPE,
main_evers: toUnits(options.mainEvers ?? DEFAULTS.mainEvers),
wrappers_cfg_keep_evers: toUnits(options.keepEvers ?? DEFAULTS.keepEvers),
main_evers: toUnitsBigIntString(options.mainEvers ?? DEFAULTS.mainEvers),
wrappers_cfg_keep_evers: toUnitsBigIntString(options.keepEvers ?? DEFAULTS.keepEvers),
wrappers_cfg: options.wrappersConfigAddress,
wrapper_deployer: await deployer.getAddress(),
});
Expand Down
14 changes: 7 additions & 7 deletions flex/exchange/tip3-token-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AccountOptionsEx,
} from "../../contracts";
import { TokenTypeInfo } from "./ever-token-type";
import { EverWallet, SignerOption, toUnits, Evr } from "../web3";
import { EverWallet, SignerOption, toUnitsBigIntString, Evr } from "../web3";

export const TIP3_TOKEN_TYPE = 0;
export type Tip3TokenTypeOptions = {
Expand Down Expand Up @@ -60,10 +60,10 @@ export async function addTip3TokenType(
pubkey: `0x${deployerPublicKey}`,
wrapper_pubkey: `0x${wrapperPublicKey}`,
super_root: options.superRoot,
wrapper_deploy_value: toUnits(options.wrapperDeployEvers ?? DEFAULTS.wrapperDeployEvers),
wrapper_keep_balance: toUnits(options.wrapperKeepEvers ?? DEFAULTS.wrapperKeepEvers),
reserve_wallet_value: toUnits(options.reserveWalletEvers ?? DEFAULTS.reserveWalletEvers),
ext_wallet_value: toUnits(options.extWalletEvers ?? DEFAULTS.extWalletEvers),
wrapper_deploy_value: toUnitsBigIntString(options.wrapperDeployEvers ?? DEFAULTS.wrapperDeployEvers),
wrapper_keep_balance: toUnitsBigIntString(options.wrapperKeepEvers ?? DEFAULTS.wrapperKeepEvers),
reserve_wallet_value: toUnitsBigIntString(options.reserveWalletEvers ?? DEFAULTS.reserveWalletEvers),
ext_wallet_value: toUnitsBigIntString(options.extWalletEvers ?? DEFAULTS.extWalletEvers),
});
await deployer.runSetWrapperCode({ code: WrapperAccount.package.code });
await deployer.runSetExtWalletCode({ code: TONTokenWalletAccount.package.code });
Expand All @@ -72,8 +72,8 @@ export async function addTip3TokenType(
const superRootOwner = await web3.accounts.get(SuperRootOwnerAccount, options.superRootOwner);
await superRootOwner.runAddWrapperType({
type: TIP3_TOKEN_TYPE,
main_evers: toUnits(options.mainEvers ?? DEFAULTS.mainEvers),
wrappers_cfg_keep_evers: toUnits(options.keepEvers ?? DEFAULTS.keepEvers),
main_evers: toUnitsBigIntString(options.mainEvers ?? DEFAULTS.mainEvers),
wrappers_cfg_keep_evers: toUnitsBigIntString(options.keepEvers ?? DEFAULTS.keepEvers),
wrappers_cfg: options.wrappersConfigAddress,
wrapper_deployer: await deployer.getAddress(),
});
Expand Down
17 changes: 9 additions & 8 deletions flex/trader/deploy-ever-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Flex } from "../flex";
import { WrapperEverAccount, AccountOptionsEx } from "../../contracts";
import { EverWallet, toUnits, uint256 } from "../web3";
import { EverWallet, TokenValue, toUnitsBigIntString, uint256 } from "../web3";
import { toUnitsBigInt } from "../web3/utils";

export type DeployTraderEverWalletOptions = {
/**
Expand All @@ -22,17 +23,17 @@ export type DeployTraderEverWalletOptions = {
/**
* Amount of EVERs to deposit
*/
tokens: number;
tokens: TokenValue;

/**
* Amount of native EVERs that the deposit message carries. Later on, DEX wallet will spend them to pay for gas.
*/
evers?: number;
evers?: TokenValue;
/**
* Minimum amount of EVERs on DEX wallet. If balance drops below this amount,
* wallet is automatically topped-up from the Trader's Index wallet.
*/
keepEvers?: number;
keepEvers?: TokenValue;
};

export type EverWalletInfo = {
Expand Down Expand Up @@ -62,17 +63,17 @@ export async function deployTraderEverWallet(
const keepEvers = options.keepEvers ?? DEFAULTS.keepEvers;
await everWallet.transfer({
dest: options.wrapperAddress,
value: toUnits(options.tokens + evers),
value: (toUnitsBigInt(options.tokens) + toUnitsBigInt(evers)).toString(),
payload: {
abi: WrapperEverAccount.package.abi,
fn: "onEverTransfer",
params: {
tokens: toUnits(options.tokens),
tokens: toUnitsBigIntString(options.tokens),
args: {
pubkey,
owner: options.clientAddress,
evers: toUnits(evers),
keep_evers: toUnits(keepEvers),
evers: toUnitsBigIntString(evers),
keep_evers: toUnitsBigIntString(keepEvers),
},
answer_addr: await everWallet.getAddress(),
},
Expand Down
8 changes: 4 additions & 4 deletions flex/trader/deploy-tip31-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
WrapperAccount,
AccountOptionsEx,
} from "../../contracts";
import { EverWallet, toUnits, uint256 } from "../web3";
import { EverWallet, toUnitsBigIntString, uint256 } from "../web3";

export type DeployTraderTip31WalletOptions = {
/**
Expand Down Expand Up @@ -85,15 +85,15 @@ export async function deployTraderTip31Wallet(
await client.getPayloadForDeployInternalWallet({
owner_addr: options.clientAddress,
owner_pubkey: pubkey,
evers: toUnits(evers),
keep_evers: toUnits(keepEvers),
evers: toUnitsBigIntString(evers),
keep_evers: toUnitsBigIntString(keepEvers),
})
).output.value0;

const everWallet = new EverWallet(flex.evr, options.everWallet);
await everWallet.transfer({
dest: options.tokenWalletAddress,
value: toUnits(options.transferEvers ?? DEFAULTS.transferEvers),
value: toUnitsBigIntString(options.transferEvers ?? DEFAULTS.transferEvers),
payload: {
abi: Tip31WalletAccount.package.abi,
fn: "transferToWallet",
Expand Down
4 changes: 2 additions & 2 deletions flex/trader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class Trader {
/**
* Tops up Trader's wallets and UserIndex account.
* Tops up to the minimum balance specified + additional value on top.
* Topup value will be equal to (TopUpOptions.minBalance - current balance + TopUpOptions.value) for each account.
* Top up value will be equal to (TopUpOptions.minBalance - current balance + TopUpOptions.value) for each account.
* @param flex
* @param options
* @returns
Expand All @@ -257,7 +257,7 @@ export class Trader {
}

/**
* Returns the list of accounts that require topup, with amount of
* Returns the list of accounts that require top up, with amount of
* TopUpResult.totalTopUpValue = (TopUpOptions.minBalance - account.balance + TopUpOptions.value)
* @param flex
* @param options
Expand Down
4 changes: 2 additions & 2 deletions flex/trader/make-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "../../contracts";
import { getWallet } from "./internals";
import { TraderOptions } from "./types";
import { toUnits, Evr, TokenValue } from "../web3";
import { toUnitsBigIntString, Evr, TokenValue } from "../web3";
import { AccountClass } from "../../contracts";
import { resolveDerivativeTransaction, SdkError } from "./processing";
import { DerivativeTransactionMessage } from "../web3/accounts";
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function makeOrder(flex: Flex, options: MakeOrderOptions): Promise<
const priceCode = (await pair.getPriceXchgCode({ salted: false })).output.value0;
const saltedPriceCode = (await pair.getPriceXchgCode({ salted: true })).output.value0;
const priceSalt = (await pair.getPriceXchgSalt()).output.value0;
const amount = toUnits(options.amount, pairDetails.major_tip3cfg.decimals);
const amount = toUnitsBigIntString(options.amount, pairDetails.major_tip3cfg.decimals);
const resolvedOrderId = options.orderId ?? (await generateRandomOrderId(flex.evr));
const orderId = `0x${BigInt(resolvedOrderId).toString(16)}`;
const price = priceToUnits(
Expand Down
Loading