Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dydxprotocol/starkex-lib

Package Overview
Dependencies
Maintainers
10
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dydxprotocol/starkex-lib - npm Package Compare versions

Comparing version 0.10.4 to 0.11.0

72

__tests__/signable/oracle-price.test.ts

@@ -9,5 +9,5 @@ /**

import {
DydxMarket,
KeyPair,
OraclePriceWithAssetId,
OraclePriceWithAssetName,
OraclePriceWithMarket,
} from '../../src/types';

@@ -19,2 +19,3 @@ import { generateKeyPairUnsafe } from '../../src/keys';

import { SignableOraclePrice } from '../../src/signable/oracle-price';
import { getSignedAssetName } from '../../src';

@@ -26,12 +27,11 @@ // Mock params.

};
const mockOraclePrice: OraclePriceWithAssetName = {
assetName: 'BTCUSD',
oracleName: 'Maker',
const mockOraclePrice: OraclePriceWithMarket = {
market: DydxMarket.BTC_USD,
oracleName: 'dYdX',
humanPrice: '11512.34',
isoTimestamp: '2020-01-01T00:00:00.000Z',
price: '11512340000000000000000',
};
const mockSignedAssetId = '425443555344000000000000000000004d616b6572';
const mockSignature = (
'06a7a118a6fa508c4f0eb77ea0efbc8d48a64d4a570d93f5c61cd886877cb920' +
'06de9006a7bbf610d583d514951c98d15b1a0f6c78846986491d2c8ca049fd55'
'020b64c5ead744a9a39bb20cee8193e15958d2f5bc065a3a31a8245d800907ae' +
'0043e5681d7fd1e0720cc578e3d076ea29dbfe902f30445da8aa74bd112aa710'
);

@@ -45,3 +45,3 @@

const result = await SignableOraclePrice
.fromPrice(mockOraclePrice)
.fromPriceWithMarket(mockOraclePrice)
.verifySignature(mockSignature, mockKeyPair.publicKey);

@@ -56,3 +56,3 @@ expect(result).toBe(true);

const result = await SignableOraclePrice
.fromPrice(mockOraclePrice)
.fromPriceWithMarket(mockOraclePrice)
.verifySignature(badSignature, mockKeyPair.publicKey);

@@ -66,3 +66,3 @@ expect(result).toBe(false);

const result = await SignableOraclePrice
.fromPrice(mockOraclePrice)
.fromPriceWithMarket(mockOraclePrice)
.verifySignature(badSignature, mockKeyPair.publicKey);

@@ -76,5 +76,5 @@ expect(result).toBe(false);

it('signs an oracle price', async () => {
it('signs an oracle price, with a market', async () => {
const signature = await SignableOraclePrice
.fromPrice(mockOraclePrice)
.fromPriceWithMarket(mockOraclePrice)
.sign(mockKeyPair.privateKey);

@@ -84,20 +84,30 @@ expect(signature).toEqual(mockSignature);

it('signs an oracle price with asset ID instead of asset name and oracle name', async () => {
const oraclePriceWithAssetId: OraclePriceWithAssetId = {
it('signs an oracle price, with an asset name', async () => {
const signature = await SignableOraclePrice
.fromPriceWithAssetName({
...mockOraclePrice,
assetName: getSignedAssetName(mockOraclePrice.market),
})
.sign(mockKeyPair.privateKey);
expect(signature).toEqual(mockSignature);
});
it('generates a different signature when the market is different', async () => {
const oraclePrice: OraclePriceWithMarket = {
...mockOraclePrice,
signedAssetId: mockSignedAssetId,
market: DydxMarket.ETH_USD,
};
const signature = await SignableOraclePrice
.fromPriceWithAssetId(oraclePriceWithAssetId)
.fromPriceWithMarket(oraclePrice)
.sign(mockKeyPair.privateKey);
expect(signature).toEqual(mockSignature);
expect(signature).not.toEqual(mockSignature);
});
it('generates a different signature when the asset ID is different', async () => {
const oraclePrice: OraclePriceWithAssetId = {
it('generates a different signature when the oracle name is different', async () => {
const oraclePrice: OraclePriceWithMarket = {
...mockOraclePrice,
signedAssetId: `${mockSignedAssetId}0`,
oracleName: 'Other',
};
const signature = await SignableOraclePrice
.fromPriceWithAssetId(oraclePrice)
.fromPriceWithMarket(oraclePrice)
.sign(mockKeyPair.privateKey);

@@ -108,3 +118,3 @@ expect(signature).not.toEqual(mockSignature);

it('generates a different signature when the timestamp is different', async () => {
const oraclePrice: OraclePriceWithAssetName = {
const oraclePrice: OraclePriceWithMarket = {
...mockOraclePrice,

@@ -114,6 +124,16 @@ isoTimestamp: new Date().toISOString(),

const signature = await SignableOraclePrice
.fromPrice(oraclePrice)
.fromPriceWithMarket(oraclePrice)
.sign(mockKeyPair.privateKey);
expect(signature).not.toEqual(mockSignature);
});
it('throws an error if the oracle name is too long', async () => {
const oraclePrice: OraclePriceWithMarket = {
...mockOraclePrice,
oracleName: 'Other2',
};
expect(
() => SignableOraclePrice.fromPriceWithMarket(oraclePrice),
).toThrow('Input does not fit in numBits=40 bits');
});
});

@@ -125,3 +145,3 @@

const keyPair: KeyPair = generateKeyPairUnsafe();
const signableOraclePrice = SignableOraclePrice.fromPrice(mockOraclePrice);
const signableOraclePrice = SignableOraclePrice.fromPriceWithMarket(mockOraclePrice);
const signature = await signableOraclePrice.sign(keyPair.privateKey);

@@ -128,0 +148,0 @@

@@ -11,2 +11,3 @@ "use strict";

const lodash_1 = __importDefault(require("lodash"));
const types_1 = require("../../src/types");
const keys_1 = require("../../src/keys");

@@ -16,2 +17,3 @@ const util_1 = require("../util");

const oracle_price_1 = require("../../src/signable/oracle-price");
const src_1 = require("../../src");
// Mock params.

@@ -23,10 +25,9 @@ const mockKeyPair = {

const mockOraclePrice = {
assetName: 'BTCUSD',
oracleName: 'Maker',
market: types_1.DydxMarket.BTC_USD,
oracleName: 'dYdX',
humanPrice: '11512.34',
isoTimestamp: '2020-01-01T00:00:00.000Z',
price: '11512340000000000000000',
};
const mockSignedAssetId = '425443555344000000000000000000004d616b6572';
const mockSignature = ('06a7a118a6fa508c4f0eb77ea0efbc8d48a64d4a570d93f5c61cd886877cb920' +
'06de9006a7bbf610d583d514951c98d15b1a0f6c78846986491d2c8ca049fd55');
const mockSignature = ('020b64c5ead744a9a39bb20cee8193e15958d2f5bc065a3a31a8245d800907ae' +
'0043e5681d7fd1e0720cc578e3d076ea29dbfe902f30445da8aa74bd112aa710');
describe('SignableOraclePrice', () => {

@@ -36,3 +37,3 @@ describe('verifySignature()', () => {

const result = await oracle_price_1.SignableOraclePrice
.fromPrice(mockOraclePrice)
.fromPriceWithMarket(mockOraclePrice)
.verifySignature(mockSignature, mockKeyPair.publicKey);

@@ -46,3 +47,3 @@ expect_1.default(result).toBe(true);

const result = await oracle_price_1.SignableOraclePrice
.fromPrice(mockOraclePrice)
.fromPriceWithMarket(mockOraclePrice)
.verifySignature(badSignature, mockKeyPair.publicKey);

@@ -55,3 +56,3 @@ expect_1.default(result).toBe(false);

const result = await oracle_price_1.SignableOraclePrice
.fromPrice(mockOraclePrice)
.fromPriceWithMarket(mockOraclePrice)
.verifySignature(badSignature, mockKeyPair.publicKey);

@@ -63,25 +64,34 @@ expect_1.default(result).toBe(false);

describe('sign()', () => {
it('signs an oracle price', async () => {
it('signs an oracle price, with a market', async () => {
const signature = await oracle_price_1.SignableOraclePrice
.fromPrice(mockOraclePrice)
.fromPriceWithMarket(mockOraclePrice)
.sign(mockKeyPair.privateKey);
expect_1.default(signature).toEqual(mockSignature);
});
it('signs an oracle price with asset ID instead of asset name and oracle name', async () => {
const oraclePriceWithAssetId = {
it('signs an oracle price, with an asset name', async () => {
const signature = await oracle_price_1.SignableOraclePrice
.fromPriceWithAssetName({
...mockOraclePrice,
signedAssetId: mockSignedAssetId,
assetName: src_1.getSignedAssetName(mockOraclePrice.market),
})
.sign(mockKeyPair.privateKey);
expect_1.default(signature).toEqual(mockSignature);
});
it('generates a different signature when the market is different', async () => {
const oraclePrice = {
...mockOraclePrice,
market: types_1.DydxMarket.ETH_USD,
};
const signature = await oracle_price_1.SignableOraclePrice
.fromPriceWithAssetId(oraclePriceWithAssetId)
.fromPriceWithMarket(oraclePrice)
.sign(mockKeyPair.privateKey);
expect_1.default(signature).toEqual(mockSignature);
expect_1.default(signature).not.toEqual(mockSignature);
});
it('generates a different signature when the asset ID is different', async () => {
it('generates a different signature when the oracle name is different', async () => {
const oraclePrice = {
...mockOraclePrice,
signedAssetId: `${mockSignedAssetId}0`,
oracleName: 'Other',
};
const signature = await oracle_price_1.SignableOraclePrice
.fromPriceWithAssetId(oraclePrice)
.fromPriceWithMarket(oraclePrice)
.sign(mockKeyPair.privateKey);

@@ -96,6 +106,13 @@ expect_1.default(signature).not.toEqual(mockSignature);

const signature = await oracle_price_1.SignableOraclePrice
.fromPrice(oraclePrice)
.fromPriceWithMarket(oraclePrice)
.sign(mockKeyPair.privateKey);
expect_1.default(signature).not.toEqual(mockSignature);
});
it('throws an error if the oracle name is too long', async () => {
const oraclePrice = {
...mockOraclePrice,
oracleName: 'Other2',
};
expect_1.default(() => oracle_price_1.SignableOraclePrice.fromPriceWithMarket(oraclePrice)).toThrow('Input does not fit in numBits=40 bits');
});
});

@@ -106,3 +123,3 @@ it('end-to-end', async () => {

const keyPair = keys_1.generateKeyPairUnsafe();
const signableOraclePrice = oracle_price_1.SignableOraclePrice.fromPrice(mockOraclePrice);
const signableOraclePrice = oracle_price_1.SignableOraclePrice.fromPriceWithMarket(mockOraclePrice);
const signature = await signableOraclePrice.sign(keyPair.privateKey);

@@ -116,2 +133,2 @@ // Expect to be valid when verifying with the right public key.

});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3JhY2xlLXByaWNlLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9fX3Rlc3RzX18vc2lnbmFibGUvb3JhY2xlLXByaWNlLnRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOztHQUVHOzs7OztBQUVILG9EQUE0QjtBQUM1QixvREFBdUI7QUFPdkIseUNBQXVEO0FBQ3ZELGtDQUE0QztBQUU1QyxxQkFBcUI7QUFDckIsa0VBQXNFO0FBRXRFLGVBQWU7QUFDZixNQUFNLFdBQVcsR0FBWTtJQUMzQixTQUFTLEVBQUUsaUVBQWlFO0lBQzVFLFVBQVUsRUFBRSxpRUFBaUU7Q0FDOUUsQ0FBQztBQUNGLE1BQU0sZUFBZSxHQUE2QjtJQUNoRCxTQUFTLEVBQUUsUUFBUTtJQUNuQixVQUFVLEVBQUUsT0FBTztJQUNuQixZQUFZLEVBQUUsMEJBQTBCO0lBQ3hD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UFTLEVBQUUsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUN4RSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUViLG1FQUFtRTtZQUNuRSxnQkFBTSxDQUNKLE1BQU0sbUJBQW1CLENBQUMsZUFBZSxDQUFDLFNBQVMsRUFBRSxXQUFXLENBQUMsU0FBUyxDQUFDLENBQzVFLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFDO1FBQ2hCLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDTixDQUFDLENBQUMsQ0FBQztBQUNMLENBQUMsQ0FBQyxDQUFDIn0=

@@ -6,3 +6,2 @@ import { DydxAsset, DydxMarket } from './types';

export declare const SYNTHETIC_ASSET_MAP: Record<DydxMarket, DydxAsset>;
export declare const SIGNED_ASSET_ID_MAP: Record<DydxMarket, string>;
/**

@@ -9,0 +8,0 @@ * The smallest unit of the asset in the Starkware system, represented in canonical (human) units.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ASSET_QUANTUM_SIZE = exports.SIGNED_ASSET_ID_MAP = exports.SYNTHETIC_ASSET_MAP = exports.COLLATERAL_ASSET_ID = exports.ASSET_ID_MAP = exports.COLLATERAL_ASSET = void 0;
exports.ASSET_QUANTUM_SIZE = exports.SYNTHETIC_ASSET_MAP = exports.COLLATERAL_ASSET_ID = exports.ASSET_ID_MAP = exports.COLLATERAL_ASSET = void 0;
const types_1 = require("./types");

@@ -18,8 +18,2 @@ exports.COLLATERAL_ASSET = types_1.DydxAsset.USDC;

};
// Asset signed by oracle price signers.
exports.SIGNED_ASSET_ID_MAP = {
[types_1.DydxMarket.BTC_USD]: '0x425443555344000000000000000000004d616b6572',
[types_1.DydxMarket.ETH_USD]: '0x455448555344000000000000000000004d616b6572',
[types_1.DydxMarket.LINK_USD]: '0xf2',
};
/**

@@ -34,2 +28,2 @@ * The smallest unit of the asset in the Starkware system, represented in canonical (human) units.

};
//# sourceMappingURL=data:application/json;base64,ey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EdBQUc7SUFDbkMsQ0FBQyxrQkFBVSxDQUFDLFFBQVEsQ0FBQyxFQUFFLGlCQUFTLENBQUMsSUFBSTtDQUN0QyxDQUFDO0FBRUY7O0dBRUc7QUFDVSxRQUFBLGtCQUFrQixHQUE4QjtJQUMzRCxDQUFDLGlCQUFTLENBQUMsSUFBSSxDQUFDLEVBQUUsTUFBTTtJQUN4QixDQUFDLGlCQUFTLENBQUMsR0FBRyxDQUFDLEVBQUUsT0FBTztJQUN4QixDQUFDLGlCQUFTLENBQUMsR0FBRyxDQUFDLEVBQUUsTUFBTTtJQUN2QixDQUFDLGlCQUFTLENBQUMsSUFBSSxDQUFDLEVBQUUsTUFBTTtDQUN6QixDQUFDIn0=
/**
* Other helper functions for converting data for Starkware.
*/
import { DydxMarket } from '../types';
/**

@@ -20,1 +21,9 @@ * Generate a nonce deterministically from an arbitrary string provided by a client.

export declare function addOrderExpirationBufferHours(expirationEpochHours: number): number;
/**
* Get the asset name to be signed, which is the market name with the hyphen removed.
*/
export declare function getSignedAssetName(market: DydxMarket): string;
/**
* Get the asset ID to be signed by a price oracle. It consists of an asset name and oracle name.
*/
export declare function getSignedAssetId(assetName: string, oracleName: string): string;

@@ -9,3 +9,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.addOrderExpirationBufferHours = exports.isoTimestampToEpochHours = exports.isoTimestampToEpochSeconds = exports.nonceFromClientId = void 0;
exports.getSignedAssetId = exports.getSignedAssetName = exports.addOrderExpirationBufferHours = exports.isoTimestampToEpochHours = exports.isoTimestampToEpochSeconds = exports.nonceFromClientId = void 0;
const crypto_1 = __importDefault(require("crypto"));

@@ -47,2 +47,21 @@ const bn_js_1 = __importDefault(require("bn.js"));

exports.addOrderExpirationBufferHours = addOrderExpirationBufferHours;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlzYy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3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ENBQUMsWUFBWSxDQUFDLENBQUMsT0FBTyxFQUFFLEdBQUcsV0FBVyxDQUFDLENBQUM7QUFDbkUsQ0FBQztBQUZELDREQUVDO0FBRUQ7O0dBRUc7QUFDSCxTQUFnQiw2QkFBNkIsQ0FBQyxvQkFBNEI7SUFDeEUsT0FBTyxvQkFBb0IsR0FBRyx5REFBNkMsQ0FBQztBQUM5RSxDQUFDO0FBRkQsc0VBRUMifQ==
/**
* Get the asset name to be signed, which is the market name with the hyphen removed.
*/
function getSignedAssetName(market) {
return market.replace('-', '');
}
exports.getSignedAssetName = getSignedAssetName;
/**
* Get the asset ID to be signed by a price oracle. It consists of an asset name and oracle name.
*/
function getSignedAssetId(assetName, oracleName) {
const assetNameBn = util_1.utf8ToBn(assetName, constants_1.ORACLE_PRICE_FIELD_BIT_LENGTHS.assetName);
const oracleNameBn = util_1.utf8ToBn(oracleName, constants_1.ORACLE_PRICE_FIELD_BIT_LENGTHS.oracleName);
const signedAssetIdBn = assetNameBn
.iushln(constants_1.ORACLE_PRICE_FIELD_BIT_LENGTHS.oracleName)
.iadd(oracleNameBn);
return signedAssetIdBn.toString(16);
}
exports.getSignedAssetId = getSignedAssetId;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlzYy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9oZWxwZXJzL21pc2MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOztHQUVHOzs7Ozs7QUFFSCxvREFBZ0M7QUFFaEMsa0RBQXVCO0FBRXZCLHNDQUFnRDtBQUNoRCxxREFJK0I7QUFHL0IsTUFBTSxTQUFTLEdBQUcsSUFBSSxlQUFFLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLElBQUksZUFBRSxDQUFDLG1DQUF1QixDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUM7QUFDdkUsTUFBTSxhQUFh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PQUFPLENBQUMsR0FBRyxFQUFFLEVBQUUsQ0FBQyxDQUFDO0FBQ2pDLENBQUM7QUFKRCxnREFJQztBQUVEOztHQUVHO0FBQ0gsU0FBZ0IsZ0JBQWdCLENBQzlCLFNBQWlCLEVBQ2pCLFVBQWtCO0lBRWxCLE1BQU0sV0FBVyxHQUFHLGVBQVEsQ0FBQyxTQUFTLEVBQUUsMENBQThCLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDbEYsTUFBTSxZQUFZLEdBQUcsZUFBUSxDQUFDLFVBQVUsRUFBRSwwQ0FBOEIsQ0FBQyxVQUFVLENBQUMsQ0FBQztJQUVyRixNQUFNLGVBQWUsR0FBRyxXQUFXO1NBQ2hDLE1BQU0sQ0FBQywwQ0FBOEIsQ0FBQyxVQUFVLENBQUM7U0FDakQsSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFDO0lBQ3RCLE9BQU8sZUFBZSxDQUFDLFFBQVEsQ0FBQyxFQUFFLENBQUMsQ0FBQztBQUN0QyxDQUFDO0FBWEQsNENBV0MifQ==
export declare const STARK_ORDER_SIGNATURE_EXPIRATION_BUFFER_HOURS: number;
export declare const ORACLE_PRICE_DECIMALS = 18;
export declare const ORDER_FIELD_BIT_LENGTHS: {

@@ -3,0 +4,0 @@ assetIdSynthetic: number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ORACLE_PRICE_FIELD_BIT_LENGTHS = exports.CONDITIONAL_TRANSFER_FIELD_BIT_LENGTHS = exports.WITHDRAWAL_FIELD_BIT_LENGTHS = exports.ORDER_FIELD_BIT_LENGTHS = exports.STARK_ORDER_SIGNATURE_EXPIRATION_BUFFER_HOURS = void 0;
exports.ORACLE_PRICE_FIELD_BIT_LENGTHS = exports.CONDITIONAL_TRANSFER_FIELD_BIT_LENGTHS = exports.WITHDRAWAL_FIELD_BIT_LENGTHS = exports.ORDER_FIELD_BIT_LENGTHS = exports.ORACLE_PRICE_DECIMALS = exports.STARK_ORDER_SIGNATURE_EXPIRATION_BUFFER_HOURS = void 0;
exports.STARK_ORDER_SIGNATURE_EXPIRATION_BUFFER_HOURS = 24 * 7; // Seven days.
exports.ORACLE_PRICE_DECIMALS = 18;
exports.ORDER_FIELD_BIT_LENGTHS = {

@@ -36,2 +37,2 @@ assetIdSynthetic: 128,

};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3NpZ25hYmxlL2NvbnN0YW50cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBYSxRQUFBLDZDQUE2QyxHQUFHLEVBQUUsR0FBRyxDQUFDLENBQUMsQ0FBQyxjQUFjO0FBRXRFLFFBQUEsdUJBQXVCLEdBQUc7SUFDckMsZ0JBQWdCLEVBQUUsR0FBRztJQUNyQixpQkFBaUIsRUFBRSxHQUFHO0lBQ3RCLFVBQVUsRUFBRSxHQUFHO0lBQ2YsY0FBYyxFQUFFLEVBQUU7SUFDbEIsS0FBSyxFQUFFLEVBQUU7SUFDVCxVQUFVLEVBQUUsRUFBRTtJQUNkLG9CQUFvQixFQUFFLEVBQUU7Q0FDekIsQ0FBQztBQUVXLFFBQUEsNEJBQTRCLEdBQUc7SUFDMUMsT0FBTyxFQUFFLEdBQUc7SUFDWixVQUFVLEVBQUUsRUFBRTtJQUNkLEtBQUssRUFBRSxFQUFFO0lBQ1QsY0FBYyxFQUFFLEVBQUU7SUFDbEIsb0JBQW9CLEVBQUUsRUFBRTtDQUN6QixDQUFDO0FBRVcsUUFBQSxzQ0FBc0MsR0FBRztJQUNwRCxPQUFPLEVBQUUsR0FBRztJQUNaLGlCQUFpQixFQUFFLEdBQUc7SUFDdEIsVUFBVSxFQUFFLEVBQUU7SUFDZCxLQUFLLEVBQUUsRUFBRTtJQUNULGNBQWMsRUFBRSxFQUFFO0lBQ2xCLG9CQUFvQixFQUFFLE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UFFLEVBQUU7SUFDZCxLQUFLLEVBQUUsRUFBRTtJQUNULGNBQWMsRUFBRSxFQUFFO0lBQ2xCLG9CQUFvQixFQUFFLEVBQUU7SUFDeEIsU0FBUyxFQUFFLEdBQUc7Q0FDZixDQUFDO0FBRVcsUUFBQSw4QkFBOEIsR0FBRztJQUM1QyxTQUFTLEVBQUUsR0FBRztJQUNkLFVBQVUsRUFBRSxFQUFFO0lBQ2QsS0FBSyxFQUFFLEdBQUc7SUFDVixxQkFBcUIsRUFBRSxFQUFFO0NBQzFCLENBQUMifQ==

@@ -8,2 +8,3 @@ import { HashFunction } from '../types';

export { SignableConditionalTransfer } from './conditional-transfer';
export { StarkSignable } from './stark-signable';
export declare const hashInWorkerThread: HashFunction;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hashInWorkerThread = exports.SignableConditionalTransfer = exports.SignableWithdrawal = exports.SignableOrder = exports.SignableOraclePrice = exports.setGlobalStarkHashImplementationNoSanityCheck = exports.setGlobalStarkHashImplementation = exports.preComputeHashes = exports.SignableApiRequest = void 0;
exports.hashInWorkerThread = exports.StarkSignable = exports.SignableConditionalTransfer = exports.SignableWithdrawal = exports.SignableOrder = exports.SignableOraclePrice = exports.setGlobalStarkHashImplementationNoSanityCheck = exports.setGlobalStarkHashImplementation = exports.preComputeHashes = exports.SignableApiRequest = void 0;
var api_request_1 = require("./api-request");

@@ -18,2 +18,4 @@ Object.defineProperty(exports, "SignableApiRequest", { enumerable: true, get: function () { return api_request_1.SignableApiRequest; } });

Object.defineProperty(exports, "SignableConditionalTransfer", { enumerable: true, get: function () { return conditional_transfer_1.SignableConditionalTransfer; } });
var stark_signable_1 = require("./stark-signable");
Object.defineProperty(exports, "StarkSignable", { enumerable: true, get: function () { return stark_signable_1.StarkSignable; } });
let maybeHashInWorkerThread = (_a, _b) => {

@@ -33,2 +35,2 @@ throw new Error('Cannot use hashInWorkerThread() since worker_threads is not available');

exports.hashInWorkerThread = maybeHashInWorkerThread;
//# sourceM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wareOraclePrice } from '../types';
import { StarkSignable } from './stark-signable';

@@ -7,7 +7,6 @@ /**

*/
export declare class SignableOraclePrice extends StarkSignable<OraclePriceWithAssetId> {
static fromPrice: typeof SignableOraclePrice.fromPriceWithAssetName;
export declare class SignableOraclePrice extends StarkSignable<StarkwareOraclePrice> {
static fromPriceWithMarket(params: OraclePriceWithMarket): SignableOraclePrice;
static fromPriceWithAssetName(params: OraclePriceWithAssetName): SignableOraclePrice;
static fromPriceWithAssetId(params: OraclePriceWithAssetId): SignableOraclePrice;
protected calculateHash(): Promise<BN>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SignableOraclePrice = void 0;
const big_js_1 = __importDefault(require("big.js"));
const helpers_1 = require("../helpers");

@@ -13,20 +17,41 @@ const util_1 = require("../lib/util");

class SignableOraclePrice extends stark_signable_1.StarkSignable {
static fromPriceWithMarket(params) {
if (typeof params.market !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: market must be a string');
}
const assetName = helpers_1.getSignedAssetName(params.market);
return SignableOraclePrice.fromPriceWithAssetName({
...params,
assetName,
});
}
static fromPriceWithAssetName(params) {
const assetNameBn = util_1.utf8ToBn(params.assetName, constants_1.ORACLE_PRICE_FIELD_BIT_LENGTHS.assetName);
const oracleNameBn = util_1.utf8ToBn(params.oracleName, constants_1.ORACLE_PRICE_FIELD_BIT_LENGTHS.oracleName);
const signedAssetId = assetNameBn
.iushln(constants_1.ORACLE_PRICE_FIELD_BIT_LENGTHS.oracleName)
.iadd(oracleNameBn);
if (typeof params.assetName !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: assetName must be a string');
}
if (typeof params.oracleName !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: oracleName must be a string');
}
if (typeof params.humanPrice !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: humanPrice must be a string');
}
if (typeof params.isoTimestamp !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: isoTimestamp must be a string');
}
const signedAssetId = helpers_1.getSignedAssetId(params.assetName, params.oracleName);
const signedPrice = new big_js_1.default(params.humanPrice);
signedPrice.e += constants_1.ORACLE_PRICE_DECIMALS;
if (!signedPrice.mod(1).eq(0)) {
throw new Error('SignableOraclePrice.fromPrice: humanPrice can have at most 18 decimals of precision');
}
const expirationEpochSeconds = helpers_1.isoTimestampToEpochSeconds(params.isoTimestamp);
return new SignableOraclePrice({
signedAssetId: signedAssetId.toString(16),
price: params.price,
isoTimestamp: params.isoTimestamp,
signedAssetId,
signedPrice: signedPrice.toFixed(0),
expirationEpochSeconds,
});
}
static fromPriceWithAssetId(params) {
return new SignableOraclePrice(params);
}
async calculateHash() {
const priceBn = util_1.decToBn(this.message.price);
const timestampEpochSecondsBn = util_1.intToBn(helpers_1.isoTimestampToEpochSeconds(this.message.isoTimestamp));
const priceBn = util_1.decToBn(this.message.signedPrice);
const timestampEpochSecondsBn = util_1.intToBn(this.message.expirationEpochSeconds);
const signedAssetId = util_1.hexToBn(this.message.signedAssetId);

@@ -46,3 +71,2 @@ if (priceBn.bitLength() > constants_1.ORACLE_PRICE_FIELD_BIT_LENGTHS.price) {

exports.SignableOraclePrice = SignableOraclePrice;
SignableOraclePrice.fromPrice = SignableOraclePrice.fromPriceWithAssetName; // Alias.
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3JhY2xlLXByaWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3NpZ25hYmxlL29yYWNsZS1wcmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFQSx3Q0FBd0Q7QUFDeEQsc0NBS3FCO0FBS3JCLDJDQUE2RDtBQUM3RCxxQ0FBMkM7QUFDM0MscURBQWlEO0FBRWpEOztHQUVHO0FBQ0gsTUFBYSxtQkFBb0IsU0FBUSw4QkFBcUM7SUFJNUU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QUFDLDBDQUE4QixDQUFDLHFCQUFxQixDQUFDO2FBQzVELElBQUksQ0FBQyx1QkFBdUIsQ0FBQyxDQUFDO1FBRWpDLE9BQU8sd0JBQWUsQ0FBQyxhQUFhLEVBQUUsaUJBQWlCLENBQUMsQ0FBQztJQUMzRCxDQUFDO0NBQ0Y7QUF2RUQsa0RBdUVDIn0=

@@ -123,10 +123,16 @@ import BN from 'bn.js';

oracleName: string;
price: string;
humanPrice: string;
isoTimestamp: string;
}
export interface OraclePriceWithAssetId {
signedAssetId: string;
price: string;
export interface OraclePriceWithMarket {
market: DydxMarket;
oracleName: string;
humanPrice: string;
isoTimestamp: string;
}
export interface StarkwareOraclePrice {
signedAssetId: string;
signedPrice: string;
expirationEpochSeconds: number;
}
export {};
{
"name": "@dydxprotocol/starkex-lib",
"version": "0.10.4",
"version": "0.11.0",
"description": "Cryptographic functions for use with StarkEx",

@@ -5,0 +5,0 @@ "main": "build/src/index.js",

@@ -22,9 +22,2 @@ import {

// Asset signed by oracle price signers.
export const SIGNED_ASSET_ID_MAP: Record<DydxMarket, string> = {
[DydxMarket.BTC_USD]: '0x425443555344000000000000000000004d616b6572',
[DydxMarket.ETH_USD]: '0x455448555344000000000000000000004d616b6572',
[DydxMarket.LINK_USD]: '0xf2',
};
/**

@@ -31,0 +24,0 @@ * The smallest unit of the asset in the Starkware system, represented in canonical (human) units.

@@ -9,7 +9,9 @@ /**

import { hexToBn } from '../lib/util';
import { hexToBn, utf8ToBn } from '../lib/util';
import {
ORACLE_PRICE_FIELD_BIT_LENGTHS,
ORDER_FIELD_BIT_LENGTHS,
STARK_ORDER_SIGNATURE_EXPIRATION_BUFFER_HOURS,
} from '../signable/constants';
import { DydxMarket } from '../types';

@@ -48,1 +50,26 @@ const MAX_NONCE = new BN(2).pow(new BN(ORDER_FIELD_BIT_LENGTHS.nonce));

}
/**
* Get the asset name to be signed, which is the market name with the hyphen removed.
*/
export function getSignedAssetName(
market: DydxMarket,
): string {
return market.replace('-', '');
}
/**
* Get the asset ID to be signed by a price oracle. It consists of an asset name and oracle name.
*/
export function getSignedAssetId(
assetName: string,
oracleName: string,
): string {
const assetNameBn = utf8ToBn(assetName, ORACLE_PRICE_FIELD_BIT_LENGTHS.assetName);
const oracleNameBn = utf8ToBn(oracleName, ORACLE_PRICE_FIELD_BIT_LENGTHS.oracleName);
const signedAssetIdBn = assetNameBn
.iushln(ORACLE_PRICE_FIELD_BIT_LENGTHS.oracleName)
.iadd(oracleNameBn);
return signedAssetIdBn.toString(16);
}
export const STARK_ORDER_SIGNATURE_EXPIRATION_BUFFER_HOURS = 24 * 7; // Seven days.
export const ORACLE_PRICE_DECIMALS = 18;

@@ -3,0 +4,0 @@ export const ORDER_FIELD_BIT_LENGTHS = {

@@ -15,2 +15,3 @@ import BN from 'bn.js';

export { SignableConditionalTransfer } from './conditional-transfer';
export { StarkSignable } from './stark-signable';

@@ -17,0 +18,0 @@ let maybeHashInWorkerThread: HashFunction = (_a: BN, _b: BN) => {

@@ -0,15 +1,23 @@

import Big from 'big.js';
import BN from 'bn.js';
import { isoTimestampToEpochSeconds } from '../helpers';
import {
getSignedAssetId,
getSignedAssetName,
isoTimestampToEpochSeconds,
} from '../helpers';
import {
decToBn,
hexToBn,
intToBn,
utf8ToBn,
} from '../lib/util';
import {
OraclePriceWithAssetName,
OraclePriceWithAssetId,
OraclePriceWithMarket,
StarkwareOraclePrice,
} from '../types';
import { ORACLE_PRICE_FIELD_BIT_LENGTHS } from './constants';
import {
ORACLE_PRICE_DECIMALS,
ORACLE_PRICE_FIELD_BIT_LENGTHS,
} from './constants';
import { getPedersenHash } from './hashes';

@@ -21,5 +29,16 @@ import { StarkSignable } from './stark-signable';

*/
export class SignableOraclePrice extends StarkSignable<OraclePriceWithAssetId> {
export class SignableOraclePrice extends StarkSignable<StarkwareOraclePrice> {
static fromPrice = SignableOraclePrice.fromPriceWithAssetName; // Alias.
static fromPriceWithMarket(
params: OraclePriceWithMarket,
): SignableOraclePrice {
if (typeof params.market !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: market must be a string');
}
const assetName = getSignedAssetName(params.market);
return SignableOraclePrice.fromPriceWithAssetName({
...params,
assetName,
});
}

@@ -29,25 +48,38 @@ static fromPriceWithAssetName(

): SignableOraclePrice {
const assetNameBn = utf8ToBn(params.assetName, ORACLE_PRICE_FIELD_BIT_LENGTHS.assetName);
const oracleNameBn = utf8ToBn(params.oracleName, ORACLE_PRICE_FIELD_BIT_LENGTHS.oracleName);
if (typeof params.assetName !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: assetName must be a string');
}
if (typeof params.oracleName !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: oracleName must be a string');
}
if (typeof params.humanPrice !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: humanPrice must be a string');
}
if (typeof params.isoTimestamp !== 'string') {
throw new Error('SignableOraclePrice.fromPrice: isoTimestamp must be a string');
}
const signedAssetId = assetNameBn
.iushln(ORACLE_PRICE_FIELD_BIT_LENGTHS.oracleName)
.iadd(oracleNameBn);
const signedAssetId = getSignedAssetId(params.assetName, params.oracleName);
const signedPrice = new Big(params.humanPrice);
signedPrice.e += ORACLE_PRICE_DECIMALS;
if (!signedPrice.mod(1).eq(0)) {
throw new Error(
'SignableOraclePrice.fromPrice: humanPrice can have at most 18 decimals of precision',
);
}
const expirationEpochSeconds = isoTimestampToEpochSeconds(params.isoTimestamp);
return new SignableOraclePrice({
signedAssetId: signedAssetId.toString(16),
price: params.price,
isoTimestamp: params.isoTimestamp,
signedAssetId,
signedPrice: signedPrice.toFixed(0),
expirationEpochSeconds,
});
}
static fromPriceWithAssetId(
params: OraclePriceWithAssetId,
): SignableOraclePrice {
return new SignableOraclePrice(params);
}
protected async calculateHash(): Promise<BN> {
const priceBn = decToBn(this.message.price);
const timestampEpochSecondsBn = intToBn(isoTimestampToEpochSeconds(this.message.isoTimestamp));
const priceBn = decToBn(this.message.signedPrice);
const timestampEpochSecondsBn = intToBn(this.message.expirationEpochSeconds);
const signedAssetId = hexToBn(this.message.signedAssetId);

@@ -54,0 +86,0 @@

@@ -157,11 +157,18 @@ import BN from 'bn.js';

oracleName: string;
price: string;
humanPrice: string;
isoTimestamp: string;
}
export interface OraclePriceWithAssetId {
export interface OraclePriceWithMarket {
market: DydxMarket;
oracleName: string;
humanPrice: string;
isoTimestamp: string;
}
export interface StarkwareOraclePrice {
// Note: This ID is specific to oracle signing and differs from the normal Starkware asset ID.
signedAssetId: string;
price: string;
isoTimestamp: string;
signedPrice: string; // Fixed point with 18 decimals.
expirationEpochSeconds: number;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc