Skip to content

Commit

Permalink
[Loopring 3.6] Demo AMM pool (#1737)
Browse files Browse the repository at this point in the history
* [protocol 3.6] AMM pool testing

* [protocol 3.6] More AMM pool testing

* [protocol 3.6] Improved AMM pool + testing

* [protocol 3.6] Small optimizations

* [protocol 3.6] Misc improvements/fixes AMM pool

* unify submitBlocksCompressedWithCallbacks (#1761)

* unify submitBlocksCompressedWithCallbacks

* unify submitBlocksCompressedWithCallbacks

* Amm approve erc20 on setup (#1762)

* approve upon setup

* approve upon setup

* allow withdraw all tokens (#1763)

* make agent explicitly inherit IAgent (#1765)

* [protocol 3.6] Small fixes

* [protocol 3.6] uint96 safe math (#1766)

* [AMM Pool] Rename variables and extract methods (#1772)

* rename variables

* extract methods

* extract methods

* [AMM Pool] Some small improvements (#1773)

* add changes based on my questions

* more

Co-authored-by: wangdong <[email protected]>
Co-authored-by: Brechtpd <[email protected]>

* [AMM pool] Changed approvals + locking logic (#1771)

* [protocol 3.6] Changed approvals + locking logic

* [protocol 3.6] LP tokens

* [protocol 3.6] Use minPoolAmountOut for joins

* [protocol 3.6] AMM pool signature assisted L1 withdrawals + fixes

* [protocol 3.6] Small improvements/fixes

Co-authored-by: Daniel Wang <[email protected]>
Co-authored-by: wangdong <[email protected]>
  • Loading branch information
3 people authored Sep 22, 2020
1 parent e8f27f2 commit c918b16
Show file tree
Hide file tree
Showing 35 changed files with 8,065 additions and 6,060 deletions.
17 changes: 14 additions & 3 deletions packages/loopring_v3.js/src/exchange_v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,18 +675,29 @@ export class ExchangeV3 {

// Get the block data from the transaction data
//const submitBlocksFunctionSignature = "0x8dadd3af"; // submitBlocks
const submitBlocksFunctionSignature = "0x14867212"; // submitBlocksCompressed
const submitBlocksFunctionSignature = "0x78e9a4f3"; // submitBlocksWithCallbacks

const transaction = await this.web3.eth.getTransaction(
event.transactionHash
);
//console.log(transaction.input);
if (transaction.input.startsWith(submitBlocksFunctionSignature)) {
const decodedCompressedInput = this.web3.eth.abi.decodeParameters(
["bytes"],
[
"bool",
"bytes",
{
"struct BlockCallback[]": {
target: "address",
blockIdx: "uint",
txIdx: "uint",
auxiliaryData: "bytes"
}
}
],
"0x" + transaction.input.slice(2 + 4 * 2)
);
const data = decompressZeros(decodedCompressedInput[0]);
const data = decompressZeros(decodedCompressedInput[1]);
// Get the inputs to commitBlock
const decodedInputs = this.web3.eth.abi.decodeParameters(
[
Expand Down
15 changes: 13 additions & 2 deletions packages/loopring_v3/circuit/Circuits/TransferCircuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class TransferCircuit : public BaseTransactionCircuit
DualVariableGadget payer_to;
DualVariableGadget payee_toAccountID;
DualVariableGadget maxFee;
DualVariableGadget putAddressesInDA;

// Check if the inputs are valid
EqualGadget isTransferTx;
Expand Down Expand Up @@ -93,6 +94,7 @@ class TransferCircuit : public BaseTransactionCircuit

// DA optimization
OrGadget da_NeedsToAddress;
OrGadget da_NeedsFromAddress;
ArrayTernaryGadget da_To;
ArrayTernaryGadget da_From;

Expand Down Expand Up @@ -136,6 +138,7 @@ class TransferCircuit : public BaseTransactionCircuit
payer_to(pb, NUM_BITS_ADDRESS, FMT(prefix, ".payer_to")),
payee_toAccountID(pb, NUM_BITS_ACCOUNT, FMT(prefix, ".payee_toAccountID")),
maxFee(pb, NUM_BITS_AMOUNT, FMT(prefix, ".maxFee")),
putAddressesInDA(pb, 1, FMT(prefix, ".putAddressesInDA")),

// Check if the inputs are valid
isTransferTx( //
Expand Down Expand Up @@ -256,17 +259,21 @@ class TransferCircuit : public BaseTransactionCircuit
// DA optimization
da_NeedsToAddress(
pb,
{toAccountValid.isNewAccount(), isConditional.result()},
{toAccountValid.isNewAccount(), isConditional.result(), putAddressesInDA.packed},
FMT(prefix, ".da_NeedsToAddress")),
da_To(
pb,
da_NeedsToAddress.result(),
to.bits,
VariableArrayT(NUM_BITS_ADDRESS, state.constants._0),
FMT(prefix, ".da_To")),
da_NeedsFromAddress(
pb,
{isConditional.result(), putAddressesInDA.packed},
FMT(prefix, ".da_NeedsFromAddress")),
da_From(
pb,
isConditional.result(),
da_NeedsFromAddress.result(),
from.bits,
VariableArrayT(NUM_BITS_ADDRESS, state.constants._0),
FMT(prefix, ".da_From")),
Expand Down Expand Up @@ -361,6 +368,7 @@ class TransferCircuit : public BaseTransactionCircuit
payer_to.generate_r1cs_witness(pb, transfer.payerTo);
payee_toAccountID.generate_r1cs_witness(pb, transfer.payeeToAccountID);
maxFee.generate_r1cs_witness(pb, transfer.maxFee);
putAddressesInDA.generate_r1cs_witness(pb, transfer.putAddressesInDA);

// Check if the inputs are valid
isTransferTx.generate_r1cs_witness();
Expand Down Expand Up @@ -401,6 +409,7 @@ class TransferCircuit : public BaseTransactionCircuit
// DA optimization
da_NeedsToAddress.generate_r1cs_witness();
da_To.generate_r1cs_witness();
da_NeedsFromAddress.generate_r1cs_witness();
da_From.generate_r1cs_witness();

// Fee as float
Expand Down Expand Up @@ -438,6 +447,7 @@ class TransferCircuit : public BaseTransactionCircuit
payer_to.generate_r1cs_constraints(true);
payee_toAccountID.generate_r1cs_constraints(true);
maxFee.generate_r1cs_constraints(true);
putAddressesInDA.generate_r1cs_constraints(true);

// Check if the inputs are valid
isTransferTx.generate_r1cs_constraints();
Expand Down Expand Up @@ -478,6 +488,7 @@ class TransferCircuit : public BaseTransactionCircuit
// DA optimization
da_NeedsToAddress.generate_r1cs_constraints();
da_To.generate_r1cs_constraints();
da_NeedsFromAddress.generate_r1cs_constraints();
da_From.generate_r1cs_constraints();

// Fee as float
Expand Down
5 changes: 4 additions & 1 deletion packages/loopring_v3/circuit/Utils/Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ static auto dummyTransfer = R"({
"payerToAccountID": 2,
"payerTo": "2",
"payeeToAccountID": 2,
"storageID": "0"
"storageID": "0",
"putAddressesInDA": false
})"_json;

static auto dummyWithdraw = R"({
Expand Down Expand Up @@ -437,6 +438,7 @@ class Transfer
ethsnarks::FieldT payerTo;
ethsnarks::FieldT payeeToAccountID;
ethsnarks::FieldT maxFee;
ethsnarks::FieldT putAddressesInDA;
ethsnarks::FieldT type;
};

Expand All @@ -457,6 +459,7 @@ static void from_json(const json &j, Transfer &transfer)
transfer.payerTo = ethsnarks::FieldT(j["payerTo"].get<std::string>().c_str());
transfer.payeeToAccountID = ethsnarks::FieldT(j.at("payeeToAccountID"));
transfer.maxFee = ethsnarks::FieldT(j["maxFee"].get<std::string>().c_str());
transfer.putAddressesInDA = ethsnarks::FieldT(j.at("putAddressesInDA").get<bool>() ? 1 : 0);
transfer.type = ethsnarks::FieldT(j.at("type"));
}

Expand Down
Loading

0 comments on commit c918b16

Please sign in to comment.