diff --git a/scripts/protobuf-patches.js b/scripts/protobuf-patches.js index cc89117f46..a07bd70b02 100755 --- a/scripts/protobuf-patches.js +++ b/scripts/protobuf-patches.js @@ -64,7 +64,8 @@ const RULE_PATCH = { 'NEMMosaicDefinition.networks': 'optional', // never used according to implementation/tests 'NEMAggregateModification.modifications': 'optional', // its valid to be undefined according to implementation/tests 'StellarAssetType.code': 'required', - 'StellarPathPaymentOp.paths': 'optional', // its valid to be undefined according to implementation/tests + 'StellarPathPaymentStrictReceiveOp.paths': 'optional', // its valid to be undefined according to implementation/tests + 'StellarPathPaymentStrictSendOp.paths': 'optional', // its valid to be undefined according to implementation/tests }; // custom types IN to trezor diff --git a/src/js/core/methods/helpers/stellarSignTx.js b/src/js/core/methods/helpers/stellarSignTx.js index 27c603b7ee..f0b80d2548 100644 --- a/src/js/core/methods/helpers/stellarSignTx.js +++ b/src/js/core/methods/helpers/stellarSignTx.js @@ -87,10 +87,10 @@ const transformOperation = (op: StellarOperation): ?StellarOperationMessage => { amount: op.amount, }; - case 'pathPayment': + case 'pathPaymentStrictReceive': validateParams(op, [{ name: 'destAmount', type: 'amount', obligatory: true }]); return { - type: 'StellarPathPaymentOp', + type: 'StellarPathPaymentStrictReceiveOp', source_account: op.source, send_asset: op.sendAsset, send_max: op.sendMax, @@ -100,10 +100,23 @@ const transformOperation = (op: StellarOperation): ?StellarOperationMessage => { paths: op.path, }; - case 'createPassiveOffer': + case 'pathPaymentStrictSend': + validateParams(op, [{ name: 'destMin', type: 'amount', obligatory: true }]); + return { + type: 'StellarPathPaymentStrictSendOp', + source_account: op.source, + send_asset: op.sendAsset, + send_amount: op.sendAmount, + destination_account: op.destination, + destination_asset: op.destAsset, + destination_min: op.destMin, + paths: op.path, + }; + + case 'createPassiveSellOffer': validateParams(op, [{ name: 'amount', type: 'amount', obligatory: true }]); return { - type: 'StellarCreatePassiveOfferOp', + type: 'StellarCreatePassiveSellOfferOp', source_account: op.source, buying_asset: op.buying, selling_asset: op.selling, @@ -112,10 +125,23 @@ const transformOperation = (op: StellarOperation): ?StellarOperationMessage => { price_d: op.price.d, }; - case 'manageOffer': + case 'manageSellOffer': + validateParams(op, [{ name: 'amount', type: 'amount', obligatory: true }]); + return { + type: 'StellarManageSellOfferOp', + source_account: op.source, + buying_asset: op.buying, + selling_asset: op.selling, + amount: op.amount, + offer_id: op.offerId || 0, + price_n: op.price.n, + price_d: op.price.d, + }; + + case 'manageBuyOffer': validateParams(op, [{ name: 'amount', type: 'amount', obligatory: true }]); return { - type: 'StellarManageOfferOp', + type: 'StellarManageBuyOfferOp', source_account: op.source, buying_asset: op.buying, selling_asset: op.selling, diff --git a/src/js/plugins/stellar/plugin.js b/src/js/plugins/stellar/plugin.js index 9d054e6091..4436f54c7d 100644 --- a/src/js/plugins/stellar/plugin.js +++ b/src/js/plugins/stellar/plugin.js @@ -56,28 +56,6 @@ const transformAsset = asset => { */ const transformAmount = amount => new BigNumber(amount).times(10000000).toString(); -/** - * Transforms StellarSdk.Operation.type to TrezorConnect.StellarTransaction.Operation.type - * @param {string} type - * @returns {string} - */ -const transformType = type => { - switch (type) { - case 'pathPaymentStrictReceive': - // case 'pathPaymentStrictSend': - return 'pathPayment'; - - case 'createPassiveSellOffer': - return 'createPassiveOffer'; - - case 'manageSellOffer': - // case 'manageBuyOffer': - return 'manageOffer'; - default: - return type; - } -}; - /** * Transforms StellarSdk.Memo to TrezorConnect.StellarTransaction.Memo * @param {string} type @@ -172,8 +150,7 @@ const transformTransaction = (path, transaction) => { operation.value = operation.value.toString('hex'); } - // transform type - operation.type = transformType(o.type); + operation.type = o.type; return operation; }); diff --git a/src/js/types/__tests__/stellar.js b/src/js/types/__tests__/stellar.js index d3b8349c0d..55a2115272 100644 --- a/src/js/types/__tests__/stellar.js +++ b/src/js/types/__tests__/stellar.js @@ -164,7 +164,7 @@ export const stellarSignTransaction = async () => { value: undefined, }, { - type: 'pathPayment', + type: 'pathPaymentStrictReceive', sendAsset: { type: 1, code: 'X', @@ -180,7 +180,7 @@ export const stellarSignTransaction = async () => { destAmount: '500111000', }, { - type: 'pathPayment', + type: 'pathPaymentStrictReceive', sendAsset: { type: 2, code: 'ABCDEFGHIJKL', @@ -208,7 +208,51 @@ export const stellarSignTransaction = async () => { ], }, { - type: 'createPassiveOffer', + type: 'pathPaymentStrictSend', + sendAsset: { + type: 1, + code: 'X', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + sendAmount: '500111000', + destination: 'GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V', + destAsset: { + type: 1, + code: 'X', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + destMin: '500111000', + }, + { + type: 'pathPaymentStrictSend', + sendAsset: { + type: 2, + code: 'ABCDEFGHIJKL', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + sendAmount: '500111000', + destination: 'GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V', + destAsset: { + type: 2, + code: 'ABCDEFGHIJKL', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + destMin: '500111000', + path: [ + { + type: 1, + code: 'X', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + { + type: 2, + code: 'ABCDEFGHIJKL', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + ], + }, + { + type: 'createPassiveSellOffer', selling: { type: 0, code: 'XLM', @@ -224,7 +268,7 @@ export const stellarSignTransaction = async () => { }, }, { - type: 'createPassiveOffer', + type: 'createPassiveSellOffer', selling: { type: 1, code: 'X', @@ -242,7 +286,24 @@ export const stellarSignTransaction = async () => { }, }, { - type: 'manageOffer', + type: 'manageSellOffer', + selling: { + type: 0, + code: 'XLM', + }, + buying: { + type: 0, + code: 'XLM', + }, + amount: '500111000', + price: { + n: 500111, + d: 10000, + }, + offerId: '101', + }, + { + type: 'manageBuyOffer', selling: { type: 0, code: 'XLM', diff --git a/src/js/types/networks/stellar.js b/src/js/types/networks/stellar.js index af97215976..7be2d285d0 100644 --- a/src/js/types/networks/stellar.js +++ b/src/js/types/networks/stellar.js @@ -9,9 +9,11 @@ import type { StellarMemoType, StellarPaymentOp, StellarCreateAccountOp, - StellarPathPaymentOp, - StellarManageOfferOp, - StellarCreatePassiveOfferOp, + StellarPathPaymentStrictSendOp, + StellarPathPaymentStrictReceiveOp, + StellarCreatePassiveSellOfferOp, + StellarManageBuyOfferOp, + StellarManageSellOfferOp, StellarSetOptionsOp, StellarChangeTrustOp, StellarAllowTrustOp, @@ -41,8 +43,8 @@ export type StellarPaymentOperation = { amount: string, // Proto: ok }; -export type StellarPathPaymentOperation = { - type: 'pathPayment', // Proto: "StellarPathPaymentOp" +export type StellarPathPaymentStrictReceiveOperation = { + type: 'pathPaymentStrictReceive', // Proto: "StellarPathPaymentStrictReceiveOp" source?: string, // Proto: "source_account" sendAsset: StellarAsset, // Proto: "send_asset" sendMax: string, // Proto: "send_max" @@ -52,8 +54,19 @@ export type StellarPathPaymentOperation = { path?: StellarAsset[], // Proto: "paths" }; -export type StellarPassiveOfferOperation = { - type: 'createPassiveOffer', // Proto: "StellarCreatePassiveOfferOp" +export type StellarPathPaymentStrictSendOperation = { + type: 'pathPaymentStrictSend', // Proto: "StellarPathPaymentStrictSendOp" + source?: string, // Proto: "source_account" + sendAsset: StellarAsset, // Proto: "send_asset" + sendAmount: string, // Proto: "send_amount" + destination: string, // Proto: "destination_account" + destAsset: StellarAsset, // Proto: "destination_asset" + destMin: string, // Proto "destination_min" + path?: StellarAsset[], // Proto: "paths" +}; + +export type StellarPassiveSellOfferOperation = { + type: 'createPassiveSellOffer', // Proto: "StellarCreatePassiveSellOfferOp" source?: string, // Proto: "source_account" buying: StellarAsset, // Proto: "buying_asset" selling: StellarAsset, // Proto: "selling_asset" @@ -61,8 +74,18 @@ export type StellarPassiveOfferOperation = { price: { n: number, d: number }, // Proto: "price_n" and "price_d" }; -export type StellarManageOfferOperation = { - type: 'manageOffer', // Proto: "StellarManageOfferOp" +export type StellarManageSellOfferOperation = { + type: 'manageSellOffer', // Proto: "StellarManageSellOfferOp" + source?: string, // Proto: "source_account" + buying: StellarAsset, // Proto: "buying_asset" + selling: StellarAsset, // Proto: "selling_asset" + amount: string, // Proto: ok + offerId?: string, // Proto: "offer_id" // not found in stellar-sdk + price: { n: number, d: number }, // Proto: "price_n" and "price_d" +}; + +export type StellarManageBuyOfferOperation = { + type: 'manageBuyOffer', // Proto: "StellarManageBuyOfferOp" source?: string, // Proto: "source_account" buying: StellarAsset, // Proto: "buying_asset" selling: StellarAsset, // Proto: "selling_asset" @@ -134,9 +157,11 @@ export type StellarInflationOperation = { export type StellarOperation = | StellarCreateAccountOperation | StellarPaymentOperation - | StellarPathPaymentOperation - | StellarPassiveOfferOperation - | StellarManageOfferOperation + | StellarPathPaymentStrictReceiveOperation + | StellarPathPaymentStrictSendOperation + | StellarPassiveSellOfferOperation + | StellarManageSellOfferOperation + | StellarManageBuyOfferOperation | StellarSetOptionsOperation | StellarChangeTrustOperation | StellarAllowTrustOperation @@ -176,14 +201,20 @@ export type StellarOperationMessage = type: 'StellarPaymentOp', } & StellarPaymentOp) | ({ - type: 'StellarPathPaymentOp', - } & StellarPathPaymentOp) + type: 'StellarPathPaymentStrictReceiveOp', + } & StellarPathPaymentStrictReceiveOp) + | ({ + type: 'StellarPathPaymentStrictSendOp', + } & StellarPathPaymentStrictSendOp) + | ({ + type: 'StellarManageSellOfferOp', + } & StellarManageSellOfferOp) | ({ - type: 'StellarManageOfferOp', - } & StellarManageOfferOp) + type: 'StellarManageBuyOfferOp', + } & StellarManageBuyOfferOp) | ({ - type: 'StellarCreatePassiveOfferOp', - } & StellarCreatePassiveOfferOp) + type: 'StellarCreatePassiveSellOfferOp', + } & StellarCreatePassiveSellOfferOp) | ({ type: 'StellarSetOptionsOp', } & StellarSetOptionsOp) diff --git a/src/js/types/trezor/protobuf.js b/src/js/types/trezor/protobuf.js index b450621582..d5c2f9960a 100644 --- a/src/js/types/trezor/protobuf.js +++ b/src/js/types/trezor/protobuf.js @@ -1925,7 +1925,7 @@ export type StellarPathPaymentStrictReceiveOp = { destination_account: string, destination_asset: StellarAsset, destination_amount: string | number, - paths: StellarAsset[], + paths?: StellarAsset[], }; // StellarPathPaymentStrictSendOp @@ -1936,7 +1936,7 @@ export type StellarPathPaymentStrictSendOp = { destination_account: string, destination_asset: StellarAsset, destination_min: string | number, - paths: StellarAsset[], + paths?: StellarAsset[], }; // StellarManageSellOfferOp diff --git a/src/ts/types/__tests__/stellar.ts b/src/ts/types/__tests__/stellar.ts index 046938524f..6b9e49994b 100644 --- a/src/ts/types/__tests__/stellar.ts +++ b/src/ts/types/__tests__/stellar.ts @@ -157,7 +157,7 @@ export const stellarSignTransaction = async () => { value: undefined, }, { - type: 'pathPayment', + type: 'pathPaymentStrictReceive', sendAsset: { type: 1, code: 'X', @@ -173,7 +173,7 @@ export const stellarSignTransaction = async () => { destAmount: '500111000', }, { - type: 'pathPayment', + type: 'pathPaymentStrictReceive', sendAsset: { type: 2, code: 'ABCDEFGHIJKL', @@ -201,7 +201,51 @@ export const stellarSignTransaction = async () => { ], }, { - type: 'createPassiveOffer', + type: 'pathPaymentStrictSend', + sendAsset: { + type: 1, + code: 'X', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + sendAmount: '500111000', + destination: 'GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V', + destAsset: { + type: 1, + code: 'X', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + destMin: '500111000', + }, + { + type: 'pathPaymentStrictSend', + sendAsset: { + type: 2, + code: 'ABCDEFGHIJKL', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + sendAmount: '500111000', + destination: 'GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V', + destAsset: { + type: 2, + code: 'ABCDEFGHIJKL', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + destMin: '500111000', + path: [ + { + type: 1, + code: 'X', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + { + type: 2, + code: 'ABCDEFGHIJKL', + issuer: 'GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC', + }, + ], + }, + { + type: 'createPassiveSellOffer', selling: { type: 0, code: 'XLM', @@ -217,7 +261,7 @@ export const stellarSignTransaction = async () => { }, }, { - type: 'createPassiveOffer', + type: 'createPassiveSellOffer', selling: { type: 1, code: 'X', @@ -235,7 +279,24 @@ export const stellarSignTransaction = async () => { }, }, { - type: 'manageOffer', + type: 'manageSellOffer', + selling: { + type: 0, + code: 'XLM', + }, + buying: { + type: 0, + code: 'XLM', + }, + amount: '500111000', + price: { + n: 500111, + d: 10000, + }, + offerId: '101', + }, + { + type: 'manageBuyOffer', selling: { type: 0, code: 'XLM', diff --git a/src/ts/types/networks/stellar.d.ts b/src/ts/types/networks/stellar.d.ts index 7eda0fe517..5a0b9cf00f 100644 --- a/src/ts/types/networks/stellar.d.ts +++ b/src/ts/types/networks/stellar.d.ts @@ -24,8 +24,8 @@ export interface StellarPaymentOperation { amount: string; // Proto: ok } -export interface StellarPathPaymentOperation { - type: 'pathPayment'; // Proto: "StellarPathPaymentOp" +export interface StellarPathPaymentStrictReceiveOperation { + type: 'pathPaymentStrictReceive'; // Proto: "StellarPathPaymentStrictReceiveOp" source?: string; // Proto: "source_account" sendAsset: StellarAsset; // Proto: "send_asset" sendMax: string; // Proto: "send_max" @@ -35,8 +35,19 @@ export interface StellarPathPaymentOperation { path?: StellarAsset[]; // Proto: "paths" } -export interface StellarPassiveOfferOperation { - type: 'createPassiveOffer'; // Proto: "StellarCreatePassiveOfferOp" +export interface StellarPathPaymentStrictSendOperation { + type: 'pathPaymentStrictSend'; // Proto: "StellarPathPaymentStrictSendOp" + source?: string; // Proto: "source_account" + sendAsset: StellarAsset; // Proto: "send_asset" + sendAmount: string; // Proto: "send_amount" + destination: string; // Proto: "destination_account" + destAsset: StellarAsset; // Proto: "destination_asset" + destMin: string; // Proto "destination_min" + path?: StellarAsset[]; // Proto: "paths" +} + +export interface StellarPassiveSellOfferOperation { + type: 'createPassiveSellOffer'; // Proto: "StellarCreatePassiveSellOfferOp" source?: string; // Proto: "source_account" buying: StellarAsset; // Proto: "buying_asset" selling: StellarAsset; // Proto: "selling_asset" @@ -44,8 +55,18 @@ export interface StellarPassiveOfferOperation { price: { n: number; d: number }; // Proto: "price_n" and "price_d" } -export interface StellarManageOfferOperation { - type: 'manageOffer'; // Proto: "StellarManageOfferOp" +export interface StellarManageSellOfferOperation { + type: 'manageSellOffer'; // Proto: "StellarManageSellOfferOp" + source?: string; // Proto: "source_account" + buying: StellarAsset; // Proto: "buying_asset" + selling: StellarAsset; // Proto: "selling_asset" + amount: string; // Proto: ok + offerId?: string; // Proto: "offer_id" // not found in stellar-sdk + price: { n: number; d: number }; // Proto: "price_n" and "price_d" +} + +export interface StellarManageBuyOfferOperation { + type: 'manageBuyOffer'; // Proto: "StellarManageBuyOfferOp" source?: string; // Proto: "source_account" buying: StellarAsset; // Proto: "buying_asset" selling: StellarAsset; // Proto: "selling_asset" @@ -117,9 +138,11 @@ export interface StellarInflationOperation { export type StellarOperation = | StellarCreateAccountOperation | StellarPaymentOperation - | StellarPathPaymentOperation - | StellarPassiveOfferOperation - | StellarManageOfferOperation + | StellarPathPaymentStrictReceiveOperation + | StellarPathPaymentStrictSendOperation + | StellarPassiveSellOfferOperation + | StellarManageSellOfferOperation + | StellarManageBuyOfferOperation | StellarSetOptionsOperation | StellarChangeTrustOperation | StellarAllowTrustOperation diff --git a/src/ts/types/trezor/protobuf.d.ts b/src/ts/types/trezor/protobuf.d.ts index 35ca75f914..319cbdd7bd 100644 --- a/src/ts/types/trezor/protobuf.d.ts +++ b/src/ts/types/trezor/protobuf.d.ts @@ -1889,7 +1889,7 @@ export type StellarPathPaymentStrictReceiveOp = { destination_account: string; destination_asset: StellarAsset; destination_amount: string | number; - paths: StellarAsset[]; + paths?: StellarAsset[]; }; // StellarPathPaymentStrictSendOp @@ -1900,7 +1900,7 @@ export type StellarPathPaymentStrictSendOp = { destination_account: string; destination_asset: StellarAsset; destination_min: string | number; - paths: StellarAsset[]; + paths?: StellarAsset[]; }; // StellarManageSellOfferOp diff --git a/tests/__fixtures__/stellarSignTransaction.js b/tests/__fixtures__/stellarSignTransaction.js index 6a2bfe303a..77c3e3beb9 100644 --- a/tests/__fixtures__/stellarSignTransaction.js +++ b/tests/__fixtures__/stellarSignTransaction.js @@ -53,18 +53,18 @@ const transformOperation = op => { line: transformAsset(op.asset), limit: op.limit.toString(), }; - case 'StellarCreatePassiveOfferOp': + case 'StellarCreatePassiveSellOfferOp': return { - type: 'createPassiveOffer', + type: 'createPassiveSellOffer', source: op.source_account, buying: transformAsset(op.buying_asset), selling: transformAsset(op.selling_asset), amount: op.amount.toString(), price: { n: op.price_n, d: op.price_d }, }; - case 'StellarManageOfferOp': + case 'StellarManageSellOfferOp': return { - type: 'manageOffer', + type: 'manageSellOffer', source: op.source_account, buying: transformAsset(op.buying_asset), selling: transformAsset(op.selling_asset), @@ -72,9 +72,19 @@ const transformOperation = op => { offerId: op.offer_id, price: { n: op.price_n, d: op.price_d }, }; - case 'StellarPathPaymentOp': + case 'StellarManageBuyOfferOp': return { - type: 'pathPayment', + type: 'manageBuyOffer', + source: op.source_account, + buying: transformAsset(op.buying_asset), + selling: transformAsset(op.selling_asset), + amount: op.amount.toString(), + offerId: op.offer_id, + price: { n: op.price_n, d: op.price_d }, + }; + case 'StellarPathPaymentStrictReceiveOp': + return { + type: 'pathPaymentStrictReceive', source: op.source_account, sendAsset: transformAsset(op.send_asset), sendMax: op.send_max, @@ -83,6 +93,17 @@ const transformOperation = op => { destAmount: op.destination_amount.toString(), path: op.paths, }; + case 'StellarPathPaymentStrictSendOp': + return { + type: 'pathPaymentStrictSend', + source: op.source_account, + sendAsset: transformAsset(op.send_asset), + sendAmount: op.send_amount, + destination: op.destination_account, + destAsset: transformAsset(op.destination_asset), + destMin: op.destination_min.toString(), + path: op.paths, + }; case 'StellarManageDataOp': return { type: 'manageData',