diff --git a/src/components/AddProposal/AddProposal.tsx b/src/components/AddProposal/AddProposal.tsx index 09691887..672b62f7 100644 --- a/src/components/AddProposal/AddProposal.tsx +++ b/src/components/AddProposal/AddProposal.tsx @@ -22,6 +22,7 @@ import { ProposalText } from "./ProposalText"; import { proposeOptions } from "./proposeOptions"; import { useAccount, useSendTransaction } from "@starknet-react/core"; import { useOptions } from "../../hooks/useOptions"; +import { stringToBigint } from "../../utils/conversions"; const strkUsdcCallPool = new Pool(STRK_ADDRESS, USDC_ADDRESS, OptionType.Call); @@ -165,15 +166,15 @@ export const AddProposal = () => { pool.quoteToken.symbol }-${pool.typeAsText.toUpperCase()}-`; return [ - name + "LONG", - name + "SHORT", + stringToBigint(name + "LONG").toString(10), + stringToBigint(name + "SHORT").toString(10), o.maturity.toString(10), decimalToMath64(o.strike), "0", // Fixed sign - pool.type, - pool.lpAddress, - pool.quoteToken.address, - pool.baseToken.address, + BigInt(pool.type).toString(10), + BigInt(pool.lpAddress).toString(10), + BigInt(pool.quoteToken.address).toString(10), + BigInt(pool.baseToken.address).toString(10), decimalToMath64(o.volatility), "0", // Fixed sign ]; diff --git a/src/components/AddProposal/proposeOptions.ts b/src/components/AddProposal/proposeOptions.ts index a0dcdeb3..ff4ea45b 100644 --- a/src/components/AddProposal/proposeOptions.ts +++ b/src/components/AddProposal/proposeOptions.ts @@ -9,16 +9,17 @@ export const proposeOptions = async ( args?: Call[] ) => Promise> ) => { + const calldata = [ + "2", // add options custom proposal prop id + options.length + 2, // length of the payload Span + AMM_ADDRESS, + options.length / 11, // length of the array of options (each option is 11 fields) + ...options, + ]; const call = { contractAddress: GOVERNANCE_ADDRESS, entrypoint: "submit_custom_proposal", - calldata: [ - "0x2", // add options custom proposal prop id - options.length + 2, // length of the payload Span - AMM_ADDRESS, - options.length / 11, // length of the array of options (each option is 11 fields) - ...options, - ], + calldata, }; debug("Executing add options proposal:", call); diff --git a/src/setupTests.ts b/src/setupTests.ts index 1dd407a6..63fb8248 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -3,3 +3,6 @@ // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom import "@testing-library/jest-dom"; +// src/setupTests.js +global.TextEncoder = require("util").TextEncoder; +global.TextDecoder = require("util").TextDecoder; // Optional if you need TextDecoder as well diff --git a/src/utils/conversions.test.ts b/src/utils/conversions.test.ts new file mode 100644 index 00000000..234c261e --- /dev/null +++ b/src/utils/conversions.test.ts @@ -0,0 +1,21 @@ +import { stringToBigint } from "./conversions"; + +describe("convert text to felt", () => { + const cases: [string, bigint][] = [ + ["STRK-USDC-CALL-LONG", 1858307286577880742802534252795740158654631495n], + ["STRK-USDC-CALL-SHORT", 475726665363937470157448768715709480645533061716n], + ["STRK-USDC-PUT-LONG", 7259012838194846651572400367370245491347015n], + ["STRK-USDC-PUT-SHORT", 1858307286577880742802534494046782875732234836n], + ["ETH-USDC-CALL-LONG", 6039427387912472877549585711181846421655111n], + ["ETH-USDC-CALL-SHORT", 1546093411305593056652693942062552713891107412n], + ]; + + test("pool names", () => { + cases.forEach(([text, felt]) => { + const result = stringToBigint(text); + expect(result === felt).toBe(true); + }); + }); +}); + +export {}; diff --git a/src/utils/conversions.ts b/src/utils/conversions.ts index 8a7d653b..33546498 100644 --- a/src/utils/conversions.ts +++ b/src/utils/conversions.ts @@ -21,3 +21,14 @@ export const bnToOptionSide = (n: BigNumberish): OptionSide => export const bnToOptionType = (n: BigNumberish): OptionType => BigInt(n) === 1n ? OptionType.Put : OptionType.Call; + +export const stringToBigint = (txt: string): bigint => { + const bText = new TextEncoder().encode(txt); + let result = 0n; + + for (let byte of bText) { + result = (result << BigInt(8)) + BigInt(byte); + } + + return result; +};