Skip to content

Commit

Permalink
Merge c55079c into c975e32
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymoussprocket committed Apr 1, 2021
2 parents c975e32 + c55079c commit d5c17f6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 36 deletions.
14 changes: 1 addition & 13 deletions grammar/tezos/Michelson.ne
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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]}" } ] }`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
42 changes: 35 additions & 7 deletions src/chain/tezos/contracts/DexterPoolHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
};
}

Expand All @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/chain/tezos/contracts/WrappedTezosHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
Expand Down
14 changes: 1 addition & 13 deletions src/chain/tezos/lexer/Michelson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}" } ] }`;
Expand Down Expand Up @@ -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"]},
Expand Down
5 changes: 4 additions & 1 deletion test/chain/tezos/TezosMessageUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');

Expand Down

0 comments on commit d5c17f6

Please sign in to comment.