From c7ebfa5e099c3b0548a9d6da6263ed166e897441 Mon Sep 17 00:00:00 2001 From: anonymoussprocket Date: Wed, 24 Mar 2021 23:18:41 -0400 Subject: [PATCH 1/6] - update dexter wrapper --- src/chain/tezos/contracts/DexterPoolHelper.ts | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/chain/tezos/contracts/DexterPoolHelper.ts b/src/chain/tezos/contracts/DexterPoolHelper.ts index 4152710f..1c401dca 100644 --- a/src/chain/tezos/contracts/DexterPoolHelper.ts +++ b/src/chain/tezos/contracts/DexterPoolHelper.ts @@ -72,13 +72,13 @@ export namespace DexterPoolHelper { return { balanceMap: Number(JSONPath({ path: '$.args[0].int', json: storageResult })[0]), - administrator: JSONPath({ path: '$.args[1].args[1].args[0].args[0].string', json: storageResult })[0], - token: JSONPath({ path: '$.args[1].args[1].args[0].args[1].string', json: storageResult })[0], - tokenBalance: Number(JSONPath({ path: '$.args[1].args[1].args[1].args[1].int', json: storageResult })[0]), - xtzBalance: Number(JSONPath({ path: '$.args[1].args[1].args[1].args[0].int', json: storageResult })[0]), - selfIsUpdatingTokenPool: (JSONPath({ path: '$.args[1].args[0].args[0].prim', json: storageResult })[0]).toString().toLowerCase().startsWith('t'), - freeze_baker: (JSONPath({ path: '$.args[1].args[0].args[1].args[0].prim', json: storageResult })[0]).toString().toLowerCase().startsWith('t'), - lqt_total: Number(JSONPath({ path: '$.args[1].args[0].args[1].args[1].int', json: storageResult })[0]) + administrator: JSONPath({ path: '$.args[2].args[0].string', json: storageResult })[0], + token: JSONPath({ path: '$.args[2].args[1].string', json: storageResult })[0], + tokenBalance: Number(JSONPath({ path: '$.args[3].int', json: storageResult })[0]), + xtzBalance: Number(JSONPath({ path: '$.args[4].int', json: storageResult })[0]), + selfIsUpdatingTokenPool: (JSONPath({ path: '$.args[1].args[0].prim', json: storageResult })[0]).toString().toLowerCase().startsWith('t'), + freeze_baker: (JSONPath({ path: '$.args[1].args[0].prim', json: storageResult })[0]).toString().toLowerCase().startsWith('t'), + lqt_total: Number(JSONPath({ path: '$.args[1].args[2].int', json: storageResult })[0]) }; } @@ -103,6 +103,34 @@ export namespace DexterPoolHelper { } } + /** + * + * @param server Destination Tezos node. + * @param address Pool contract address. + * @param account + * @returns Raw values that are not scaled. + */ + export async function getAccountPoolShare(server: string, address: string, account: string): Promise<{token: number, xtz: number}> { + try { + const storage = await getSimpleStorage(server, address); + + const packedKey = TezosMessageUtils.encodeBigMapKey(Buffer.from(TezosMessageUtils.writePackedData(account, 'address'), 'hex')); + const mapResult = await TezosNodeReader.getValueForBigMapKey(server, storage.balanceMap, packedKey); + + if (mapResult === undefined) { throw new Error(`Map ${storage.balanceMap} does not contain a record for ${account}`); } + + const poolBalance = bigInt(JSONPath({ path: '$.args[0].int', json: mapResult })[0]); + + const poolTotal = bigInt(storage.lqt_total); + const tokenBalance = bigInt(storage.tokenBalance); + const xtzBalance = bigInt(storage.xtzBalance); + + return { token: tokenBalance.multiply(poolBalance).divide(poolTotal).toJSNumber(), xtz: xtzBalance.multiply(poolBalance).divide(poolTotal).toJSNumber() }; + } catch (error) { + return { token: 0, xtz: 0 }; + } + } + /** * Queries the Tezos node for the liquidity balance approval for a given spender on the requested account. * From b465d98ff59958ab15c7dfa1215ab18bb8a6a979 Mon Sep 17 00:00:00 2001 From: anonymoussprocket Date: Wed, 24 Mar 2021 23:19:50 -0400 Subject: [PATCH 2/6] - update michelson parser to remove DUP n macro --- grammar/tezos/Michelson.ne | 14 +------------- src/chain/tezos/lexer/Michelson.ts | 14 +------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/grammar/tezos/Michelson.ne b/grammar/tezos/Michelson.ne index 15d63807..a6c2df89 100644 --- a/grammar/tezos/Michelson.ne +++ b/grammar/tezos/Michelson.ne @@ -182,7 +182,7 @@ instruction -> | "PUSH" _ type _ %lbrace %rbrace {% pushToJson %} | "PUSH" (_ %annot):+ _ type _ data {% pushWithAnnotsToJson %} | "DIP" _ [0-9]:+ _ subInstruction {% dipnToJson %} - | "DUP" _ [0-9]:+ {% dupnToJson %} + | "DUP" _ [0-9]:+ {% dignToJson %} | "DUP" {% keywordToJson %} | "DUP" (_ %annot):+ _ {% keywordToJson %} | "DIG" _ [0-9]:+ {% dignToJson %} @@ -624,18 +624,6 @@ semicolons -> [;]:? const dipnToJson = d => (d.length > 4) ? `{ "prim": "${d[0]}", "args": [ { "int": "${d[2]}" }, [ ${d[4]} ] ] }` : `{ "prim": "${d[0]}", "args": [ ${d[2]} ] }`; - const dupnToJson = d => { - const n = Number(d[2]); - - if (n === 1) { - return '{ "prim": "DUP" }'; - } else if (n === 2) { - return '[{ "prim": "DIP", "args": [[ {"prim": "DUP"} ]] }, { "prim": "SWAP" }]'; - } else { - return `[{ "prim": "DIP", "args": [ {"int": "${n - 1}"}, [{ "prim": "DUP" }] ] }, { "prim": "DIG", "args": [ {"int": "${n}"} ] }]`; - } - }; - const dignToJson = d => `{ "prim": "${d[0]}", "args": [ { "int": "${d[2]}" } ] }`; const dropnToJson = d => `{ "prim": "${d[0]}", "args": [ { "int": "${d[2]}" } ] }`; diff --git a/src/chain/tezos/lexer/Michelson.ts b/src/chain/tezos/lexer/Michelson.ts index ba9ce678..201df109 100644 --- a/src/chain/tezos/lexer/Michelson.ts +++ b/src/chain/tezos/lexer/Michelson.ts @@ -519,18 +519,6 @@ const lexer = moo.compile({ const dipnToJson = d => (d.length > 4) ? `{ "prim": "${d[0]}", "args": [ { "int": "${d[2]}" }, [ ${d[4]} ] ] }` : `{ "prim": "${d[0]}", "args": [ ${d[2]} ] }`; - const dupnToJson = d => { - const n = Number(d[2]); - - if (n === 1) { - return '{ "prim": "DUP" }'; - } else if (n === 2) { - return '[{ "prim": "DIP", "args": [[ {"prim": "DUP"} ]] }, { "prim": "SWAP" }]'; - } else { - return `[{ "prim": "DIP", "args": [ {"int": "${n - 1}"}, [{ "prim": "DUP" }] ] }, { "prim": "DIG", "args": [ {"int": "${n}"} ] }]`; - } - }; - const dignToJson = d => `{ "prim": "${d[0]}", "args": [ { "int": "${d[2]}" } ] }`; const dropnToJson = d => `{ "prim": "${d[0]}", "args": [ { "int": "${d[2]}" } ] }`; @@ -795,7 +783,7 @@ const grammar: Grammar = { {"name": "instruction", "symbols": [{"literal":"DIP"}, "_", "instruction$ebnf$9", "_", "subInstruction"], "postprocess": dipnToJson}, {"name": "instruction$ebnf$10", "symbols": [/[0-9]/]}, {"name": "instruction$ebnf$10", "symbols": ["instruction$ebnf$10", /[0-9]/], "postprocess": (d) => d[0].concat([d[1]])}, - {"name": "instruction", "symbols": [{"literal":"DUP"}, "_", "instruction$ebnf$10"], "postprocess": dupnToJson}, + {"name": "instruction", "symbols": [{"literal":"DUP"}, "_", "instruction$ebnf$10"], "postprocess": dignToJson}, {"name": "instruction", "symbols": [{"literal":"DUP"}], "postprocess": keywordToJson}, {"name": "instruction$ebnf$11$subexpression$1", "symbols": ["_", (lexer.has("annot") ? {type: "annot"} : annot)]}, {"name": "instruction$ebnf$11", "symbols": ["instruction$ebnf$11$subexpression$1"]}, From d6a5dab744af4c1a7e93eaed819305dfbd8031a4 Mon Sep 17 00:00:00 2001 From: anonymoussprocket Date: Wed, 24 Mar 2021 23:19:56 -0400 Subject: [PATCH 3/6] - version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0438c03d..12987642 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "conseiljs", - "version": "5.0.8-1", + "version": "5.0.8-2", "description": "Client-side library for Tezos dApp development.", "browser": "dist/index-web.js", "main": "dist/index.js", From 86171287a0f178cec3b5c9cbd0abdcec5b84cf3d Mon Sep 17 00:00:00 2001 From: anonymoussprocket Date: Wed, 31 Mar 2021 22:56:40 -0400 Subject: [PATCH 4/6] - test update --- test/chain/tezos/TezosMessageUtil.spec.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/chain/tezos/TezosMessageUtil.spec.ts b/test/chain/tezos/TezosMessageUtil.spec.ts index eef321d6..ae26a48e 100644 --- a/test/chain/tezos/TezosMessageUtil.spec.ts +++ b/test/chain/tezos/TezosMessageUtil.spec.ts @@ -135,7 +135,7 @@ describe('Tezos P2P message codec helper tests', () => { expect(result).to.equal('8b858b81c289bfcefc2a'); }); - it('test findInt function', () => { + it('test findInt function', () => { let result = TezosMessageUtils.findInt('d3dade57fae2', 0); expect(result.value).to.equal(184003923); expect(result.length).to.equal(8); @@ -171,6 +171,9 @@ describe('Tezos P2P message codec helper tests', () => { result = TezosMessageUtils.writePackedData('tz1eEnQhbwf6trb8Q8mPb2RaPkNk2rN7BKi8', 'address'); expect(result).to.equal('050a000000160000cc04e65d3e38e4e8059041f27a649c76630f95e2'); + result = TezosMessageUtils.writePackedData('tz1eEnQhbwf6trb8Q8mPb2RaPkNk2rN7BKi8', 'key_hash'); + expect(result).to.equal('050a000000160000cc04e65d3e38e4e8059041f27a649c76630f95e2'); + result = TezosMessageUtils.writePackedData('Tezos Tacos Nachos', 'string'); expect(result).to.equal('05010000001254657a6f73205461636f73204e6163686f73'); @@ -279,6 +282,18 @@ describe('Tezos P2P message codec helper tests', () => { }); }); + TezosMessageUtils.writePublicKey + sppk7ZZkGTcFJPrta2ikEeCziy3DVSxgJPjNs4d6xRHHGABydLkfwHi + p2pk65XEYA4x2SgD8G8HqruF8ZP3rB48agaAfUHoGdDtdsYwhnrNPg8 + + readKeyWithHint + readSignatureWithHint + writeSignatureWithHint + + computeOperationHash + + calculateContractAddress + it('test signature codec', () => { //readSignatureWithHint //writeSignatureWithHint From 97b2ff5bc17ed1f9cde11e0996bda25152e462f3 Mon Sep 17 00:00:00 2001 From: anonymoussprocket Date: Wed, 31 Mar 2021 22:57:14 -0400 Subject: [PATCH 5/6] - test update --- test/chain/tezos/TezosMessageUtil.spec.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/chain/tezos/TezosMessageUtil.spec.ts b/test/chain/tezos/TezosMessageUtil.spec.ts index ae26a48e..c9e54df5 100644 --- a/test/chain/tezos/TezosMessageUtil.spec.ts +++ b/test/chain/tezos/TezosMessageUtil.spec.ts @@ -282,18 +282,6 @@ describe('Tezos P2P message codec helper tests', () => { }); }); - TezosMessageUtils.writePublicKey - sppk7ZZkGTcFJPrta2ikEeCziy3DVSxgJPjNs4d6xRHHGABydLkfwHi - p2pk65XEYA4x2SgD8G8HqruF8ZP3rB48agaAfUHoGdDtdsYwhnrNPg8 - - readKeyWithHint - readSignatureWithHint - writeSignatureWithHint - - computeOperationHash - - calculateContractAddress - it('test signature codec', () => { //readSignatureWithHint //writeSignatureWithHint From c55079cc281217a6cc9108d7ccb45dff918ca122 Mon Sep 17 00:00:00 2001 From: anonymoussprocket Date: Wed, 31 Mar 2021 22:57:53 -0400 Subject: [PATCH 6/6] - STKR balance transfer fix --- src/chain/tezos/contracts/WrappedTezosHelper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chain/tezos/contracts/WrappedTezosHelper.ts b/src/chain/tezos/contracts/WrappedTezosHelper.ts index c17a5c8d..69ad5fd9 100644 --- a/src/chain/tezos/contracts/WrappedTezosHelper.ts +++ b/src/chain/tezos/contracts/WrappedTezosHelper.ts @@ -190,7 +190,7 @@ export namespace WrappedTezosHelper { fee: number, sourceAddress: string, destinationAddress: string, - amount: number, + amount: number | string, gasLimit: number = 51_300, storageLimit: number = 70 ): Promise {