Comparing version 0.0.12 to 0.0.13
@@ -18,2 +18,3 @@ import algosdk, { ABIValue } from "algosdk"; | ||
value: T; | ||
inners: Record<string, any>[]; | ||
constructor(result: algosdk.ABIResult | undefined, value?: T); | ||
@@ -20,0 +21,0 @@ } |
@@ -73,2 +73,12 @@ "use strict"; | ||
this.txInfo = result.txInfo; | ||
this.inners = []; | ||
if (result.txInfo !== undefined && 'inner-txns' in result.txInfo) { | ||
var outer_1 = result.txInfo['txn']['txn']; | ||
this.inners = result.txInfo['inner-txns'].map(function (itxn) { | ||
var et = itxn['txn']['txn']; | ||
et.gen = outer_1.gen; | ||
et.gh = outer_1.gh; | ||
return algosdk_1.default.Transaction.from_obj_for_encoding(itxn['txn']['txn']); | ||
}); | ||
} | ||
this.returnValue = result.returnValue; | ||
@@ -354,3 +364,2 @@ this.value = value; | ||
} | ||
console.log(processedArgs); | ||
atc.addMethodCall(__assign({ appID: this.appId, method: method, methodArgs: processedArgs, sender: this.getSender(), suggestedParams: sp, signer: this.signer }, txParams)); | ||
@@ -357,0 +366,0 @@ return [2 /*return*/, atc]; |
@@ -47,9 +47,9 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var acct, appClient, _a, appId, appAddr, txId, _b, assetA, assetB, bootstrapResult, _c, _d, _e, _f, poolToken, optInToAsset, _g, _h, fundResult, _j, _k, _l, _m, _o, _p, _q; | ||
var _r, _s, _t, _u; | ||
return __generator(this, function (_v) { | ||
switch (_v.label) { | ||
var acct, appClient, _a, appId, appAddr, txId, _b, assetA, assetB, bootstrapResult, _c, _d, _e, _f, poolToken, optInToAsset, _g, _h, fundResult, _j, _k, _l, _m, _o, _p, _q, swapAtoB, _r, _s, _t, _u, swapBtoA, _v, _w, _x, _y, burnResult, _z, _0, _1, _2, _3, aRcv, bRcv; | ||
var _4, _5, _6, _7, _8, _9, _10; | ||
return __generator(this, function (_11) { | ||
switch (_11.label) { | ||
case 0: return [4 /*yield*/, (0, __1.getAccounts)()]; | ||
case 1: | ||
acct = (_v.sent()).pop(); | ||
acct = (_11.sent()).pop(); | ||
appClient = new constantproductamm_client_1.ConstantProductAMM({ | ||
@@ -62,11 +62,11 @@ client: (0, __1.getAlgodClient)(), | ||
case 2: | ||
_a = _v.sent(), appId = _a[0], appAddr = _a[1], txId = _a[2]; | ||
_a = _11.sent(), appId = _a[0], appAddr = _a[1], txId = _a[2]; | ||
console.log("Created app ".concat(appId, " with address ").concat(appAddr, " in tx ").concat(txId)); | ||
return [4 /*yield*/, createAssets(appClient.client, acct)]; | ||
case 3: | ||
_b = _v.sent(), assetA = _b[0], assetB = _b[1]; | ||
_b = _11.sent(), assetA = _b[0], assetB = _b[1]; | ||
console.log("created ".concat(assetA, ", ").concat(assetB)); | ||
_d = (_c = appClient).bootstrap; | ||
_f = (_e = algosdk_1.default).makePaymentTxnWithSuggestedParamsFromObject; | ||
_r = { | ||
_4 = { | ||
from: acct.addr, | ||
@@ -76,12 +76,12 @@ to: appAddr | ||
return [4 /*yield*/, appClient.client.getTransactionParams().do()]; | ||
case 4: return [4 /*yield*/, _d.apply(_c, [_f.apply(_e, [(_r.suggestedParams = _v.sent(), | ||
_r.amount = BigInt(1e6), | ||
_r)]), | ||
case 4: return [4 /*yield*/, _d.apply(_c, [_f.apply(_e, [(_4.suggestedParams = _11.sent(), | ||
_4.amount = BigInt(1e6), | ||
_4)]), | ||
assetA, | ||
assetB])]; | ||
case 5: | ||
bootstrapResult = _v.sent(); | ||
bootstrapResult = _11.sent(); | ||
poolToken = bootstrapResult.value; | ||
_h = (_g = algosdk_1.default).makeAssetTransferTxnWithSuggestedParamsFromObject; | ||
_s = { | ||
_5 = { | ||
from: acct.addr, | ||
@@ -92,15 +92,15 @@ to: acct.addr | ||
case 6: | ||
optInToAsset = _h.apply(_g, [(_s.suggestedParams = _v.sent(), | ||
_s.amount = 0, | ||
_s.assetIndex = Number(poolToken), | ||
_s)]); | ||
return [4 /*yield*/, appClient.client.sendRawTransaction(optInToAsset.signTxn(acct.privateKey)).do()]; | ||
optInToAsset = _h.apply(_g, [(_5.suggestedParams = _11.sent(), | ||
_5.amount = 0, | ||
_5.assetIndex = Number(poolToken), | ||
_5)]); | ||
appClient.client.sendRawTransaction(optInToAsset.signTxn(acct.privateKey)).do(); | ||
return [4 /*yield*/, algosdk_1.default.waitForConfirmation(appClient.client, optInToAsset.txID(), 4) | ||
// Fund the pool with initial liquidity | ||
]; | ||
case 7: | ||
_v.sent(); | ||
return [4 /*yield*/, algosdk_1.default.waitForConfirmation(appClient.client, optInToAsset.txID(), 4)]; | ||
case 8: | ||
_v.sent(); | ||
_11.sent(); | ||
_k = (_j = appClient).mint; | ||
_m = (_l = algosdk_1.default).makeAssetTransferTxnWithSuggestedParamsFromObject; | ||
_t = { | ||
_6 = { | ||
from: acct.addr, | ||
@@ -110,9 +110,9 @@ to: appAddr | ||
return [4 /*yield*/, appClient.client.getTransactionParams().do()]; | ||
case 9: | ||
_o = [_m.apply(_l, [(_t.suggestedParams = _v.sent(), | ||
_t.amount = BigInt(1e6), | ||
_t.assetIndex = Number(assetA), | ||
_t)])]; | ||
case 8: | ||
_o = [_m.apply(_l, [(_6.suggestedParams = _11.sent(), | ||
_6.amount = BigInt(1e8), | ||
_6.assetIndex = Number(assetA), | ||
_6)])]; | ||
_q = (_p = algosdk_1.default).makeAssetTransferTxnWithSuggestedParamsFromObject; | ||
_u = { | ||
_7 = { | ||
from: acct.addr, | ||
@@ -122,12 +122,62 @@ to: appAddr | ||
return [4 /*yield*/, appClient.client.getTransactionParams().do()]; | ||
case 10: return [4 /*yield*/, _k.apply(_j, _o.concat([_q.apply(_p, [(_u.suggestedParams = _v.sent(), | ||
_u.amount = BigInt(1e6), | ||
_u.assetIndex = Number(assetB), | ||
_u)]), | ||
case 9: return [4 /*yield*/, _k.apply(_j, _o.concat([_q.apply(_p, [(_7.suggestedParams = _11.sent(), | ||
_7.amount = BigInt(1e6), | ||
_7.assetIndex = Number(assetB), | ||
_7)]), | ||
poolToken, | ||
assetA, | ||
assetB]))]; | ||
case 11: | ||
fundResult = _v.sent(); | ||
console.log(fundResult.returnValue); | ||
case 10: | ||
fundResult = _11.sent(); | ||
console.log("Received ".concat(fundResult.inners[0].aamt, " pool tokens")); | ||
_s = (_r = appClient).swap; | ||
_u = (_t = algosdk_1.default).makeAssetTransferTxnWithSuggestedParamsFromObject; | ||
_8 = { | ||
from: acct.addr, | ||
to: appAddr | ||
}; | ||
return [4 /*yield*/, appClient.client.getTransactionParams().do()]; | ||
case 11: return [4 /*yield*/, _s.apply(_r, [_u.apply(_t, [(_8.suggestedParams = _11.sent(), | ||
_8.amount = BigInt(1e3), | ||
_8.assetIndex = Number(assetA), | ||
_8)]), | ||
assetA, | ||
assetB])]; | ||
case 12: | ||
swapAtoB = _11.sent(); | ||
console.log("Received ".concat(swapAtoB.inners[0].aamt, " B tokens")); | ||
_w = (_v = appClient).swap; | ||
_y = (_x = algosdk_1.default).makeAssetTransferTxnWithSuggestedParamsFromObject; | ||
_9 = { | ||
from: acct.addr, | ||
to: appAddr | ||
}; | ||
return [4 /*yield*/, appClient.client.getTransactionParams().do()]; | ||
case 13: return [4 /*yield*/, _w.apply(_v, [_y.apply(_x, [(_9.suggestedParams = _11.sent(), | ||
_9.amount = BigInt(1e3), | ||
_9.assetIndex = Number(assetB), | ||
_9)]), | ||
assetA, | ||
assetB])]; | ||
case 14: | ||
swapBtoA = _11.sent(); | ||
console.log("Received ".concat(swapBtoA.inners[0].aamt, " A tokens")); | ||
_0 = (_z = appClient).burn; | ||
_2 = (_1 = algosdk_1.default).makeAssetTransferTxnWithSuggestedParamsFromObject; | ||
_10 = { | ||
from: acct.addr, | ||
to: appAddr | ||
}; | ||
return [4 /*yield*/, appClient.client.getTransactionParams().do()]; | ||
case 15: return [4 /*yield*/, _0.apply(_z, [_2.apply(_1, [(_10.suggestedParams = _11.sent(), | ||
_10.amount = BigInt(10), | ||
_10.assetIndex = Number(poolToken), | ||
_10)]), | ||
poolToken, | ||
assetA, | ||
assetB])]; | ||
case 16: | ||
burnResult = _11.sent(); | ||
_3 = burnResult.inners, aRcv = _3[0], bRcv = _3[1]; | ||
console.log("Received ".concat(aRcv.aamt, " A tokens and ").concat(bRcv.aamt, " B tokens")); | ||
return [2 /*return*/]; | ||
@@ -149,3 +199,3 @@ } | ||
suggestedParams: sp, | ||
total: 10000000, | ||
total: BigInt(1e10), | ||
decimals: 0, | ||
@@ -159,3 +209,3 @@ defaultFrozen: false, | ||
suggestedParams: sp, | ||
total: 10000000, | ||
total: BigInt(1e9), | ||
decimals: 0, | ||
@@ -162,0 +212,0 @@ defaultFrozen: false, |
{ | ||
"name": "beaker-ts", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -1,2 +0,2 @@ | ||
import algosdk, { ABIValue, SuggestedParams, TransactionParams } from "algosdk"; | ||
import algosdk, { ABIValue, EncodedTransaction, SuggestedParams, TransactionParams } from "algosdk"; | ||
@@ -31,2 +31,3 @@ import { getStateSchema, Schema } from "../"; | ||
value: T; | ||
inners: Record<string, any>[]; | ||
@@ -39,2 +40,15 @@ constructor(result: algosdk.ABIResult | undefined, value?: T){ | ||
this.txInfo = result.txInfo; | ||
this.inners = []; | ||
if (result.txInfo !== undefined && 'inner-txns' in result.txInfo){ | ||
const outer = result.txInfo['txn']['txn'] as EncodedTransaction | ||
this.inners = result.txInfo['inner-txns'].map((itxn: any)=>{ | ||
const et = itxn['txn']['txn'] as EncodedTransaction | ||
et.gen = outer.gen | ||
et.gh = outer.gh | ||
return algosdk.Transaction.from_obj_for_encoding(itxn['txn']['txn'] as EncodedTransaction) | ||
}) | ||
} | ||
this.returnValue = result.returnValue | ||
@@ -299,4 +313,2 @@ this.value = value | ||
console.log(processedArgs) | ||
atc.addMethodCall({ | ||
@@ -303,0 +315,0 @@ appID: this.appId, |
@@ -38,2 +38,3 @@ import algosdk from "algosdk"; | ||
// Opt user into new pool token | ||
const optInToAsset = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ | ||
@@ -46,7 +47,6 @@ from: acct.addr, | ||
}) | ||
await appClient.client.sendRawTransaction(optInToAsset.signTxn(acct.privateKey)).do() | ||
appClient.client.sendRawTransaction(optInToAsset.signTxn(acct.privateKey)).do() | ||
await algosdk.waitForConfirmation(appClient.client, optInToAsset.txID(), 4) | ||
// Fund the pool with initial liquidity | ||
const fundResult = await appClient.mint( | ||
@@ -57,3 +57,3 @@ algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ | ||
suggestedParams: await appClient.client.getTransactionParams().do(), | ||
amount: BigInt(1e6), | ||
amount: BigInt(1e8), | ||
assetIndex: Number(assetA), | ||
@@ -72,6 +72,49 @@ }), | ||
) | ||
console.log(`Received ${fundResult.inners[0].aamt} pool tokens`) | ||
console.log(fundResult.returnValue) | ||
// Try to swap A for B | ||
const swapAtoB = await appClient.swap( | ||
algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ | ||
from: acct.addr, | ||
to: appAddr, | ||
suggestedParams: await appClient.client.getTransactionParams().do(), | ||
amount: BigInt(1e3), | ||
assetIndex: Number(assetA), | ||
}), | ||
assetA, | ||
assetB | ||
) | ||
console.log(`Received ${swapAtoB.inners[0].aamt} B tokens`) | ||
// Try to swap B for A | ||
const swapBtoA = await appClient.swap( | ||
algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ | ||
from: acct.addr, | ||
to: appAddr, | ||
suggestedParams: await appClient.client.getTransactionParams().do(), | ||
amount: BigInt(1e3), | ||
assetIndex: Number(assetB), | ||
}), | ||
assetA, | ||
assetB | ||
) | ||
console.log(`Received ${swapBtoA.inners[0].aamt} A tokens`) | ||
// Burn some pool tokens | ||
const burnResult = await appClient.burn( | ||
algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ | ||
from: acct.addr, | ||
to: appAddr, | ||
suggestedParams: await appClient.client.getTransactionParams().do(), | ||
amount: BigInt(10), | ||
assetIndex: Number(poolToken), | ||
}), | ||
poolToken, | ||
assetA, | ||
assetB | ||
) | ||
const [aRcv, bRcv] = burnResult.inners | ||
console.log(`Received ${aRcv.aamt} A tokens and ${bRcv.aamt} B tokens`) | ||
})(); | ||
@@ -87,3 +130,3 @@ | ||
suggestedParams: sp, | ||
total: 10000000, | ||
total: BigInt(1e10), | ||
decimals: 0, | ||
@@ -98,3 +141,3 @@ defaultFrozen: false, | ||
suggestedParams: sp, | ||
total: 10000000, | ||
total: BigInt(1e9), | ||
decimals: 0, | ||
@@ -101,0 +144,0 @@ defaultFrozen: false, |
@@ -5,12 +5,9 @@ import { | ||
DynamicSchemaValueSpec, | ||
HintSpec, | ||
Hint, | ||
Schema, | ||
Struct, | ||
SchemaSpec, | ||
AppSources, | ||
} from "./appspec"; | ||
import algosdk from "algosdk"; | ||
import ts, { factory, NodeFactory } from "typescript"; | ||
import ts, { factory } from "typescript"; | ||
import { writeFileSync } from "fs"; | ||
@@ -17,0 +14,0 @@ |
318740
5019