algosdk 1.24.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/browser/algosdk.min.js +1 -1
- package/dist/browser/algosdk.min.js.LICENSE.txt +0 -18
- package/dist/browser/algosdk.min.js.map +1 -1
- package/dist/cjs/client/v2/algod/algod.js +1 -1
- package/dist/cjs/client/v2/algod/algod.js.map +1 -1
- package/dist/cjs/client/v2/algod/models/types.js +161 -123
- package/dist/cjs/client/v2/algod/models/types.js.map +1 -1
- package/dist/cjs/client/v2/indexer/lookupAssetTransactions.js +0 -7
- package/dist/cjs/client/v2/indexer/lookupAssetTransactions.js.map +1 -1
- package/dist/cjs/dryrun.js +16 -7
- package/dist/cjs/dryrun.js.map +1 -1
- package/dist/cjs/logicsig.js +3 -14
- package/dist/cjs/logicsig.js.map +1 -1
- package/dist/cjs/main.js +3 -6
- package/dist/cjs/main.js.map +1 -1
- package/dist/cjs/makeTxn.js +1 -193
- package/dist/cjs/makeTxn.js.map +1 -1
- package/dist/esm/client/v2/algod/algod.js +1 -1
- package/dist/esm/client/v2/algod/algod.js.map +1 -1
- package/dist/esm/client/v2/algod/models/types.js +160 -120
- package/dist/esm/client/v2/algod/models/types.js.map +1 -1
- package/dist/esm/client/v2/indexer/lookupAssetTransactions.js +0 -7
- package/dist/esm/client/v2/indexer/lookupAssetTransactions.js.map +1 -1
- package/dist/esm/dryrun.js +16 -7
- package/dist/esm/dryrun.js.map +1 -1
- package/dist/esm/logicsig.js +2 -12
- package/dist/esm/logicsig.js.map +1 -1
- package/dist/esm/main.js +1 -4
- package/dist/esm/main.js.map +1 -1
- package/dist/esm/makeTxn.js +0 -185
- package/dist/esm/makeTxn.js.map +1 -1
- package/dist/types/client/v2/algod/algod.d.ts +1 -1
- package/dist/types/client/v2/algod/models/types.d.ts +122 -67
- package/dist/types/client/v2/indexer/lookupAssetTransactions.d.ts +0 -4
- package/dist/types/logicsig.d.ts +2 -10
- package/dist/types/main.d.ts +1 -3
- package/dist/types/makeTxn.d.ts +1 -147
- package/dist/types/types/transactions/encoded.d.ts +0 -15
- package/package.json +1 -1
- package/src/client/v2/algod/algod.ts +2 -2
- package/src/client/v2/algod/models/types.ts +318 -249
- package/src/client/v2/indexer/lookupAssetTransactions.ts +0 -8
- package/src/dryrun.ts +13 -13
- package/src/logicsig.ts +2 -13
- package/src/main.ts +1 -5
- package/src/makeTxn.ts +0 -421
- package/src/types/transactions/encoded.ts +0 -17
- package/dist/cjs/client/algod.js +0 -295
- package/dist/cjs/client/algod.js.map +0 -1
- package/dist/cjs/logic/langspec.json +0 -2014
- package/dist/cjs/logic/logic.js +0 -262
- package/dist/cjs/logic/logic.js.map +0 -1
- package/dist/cjs/logicTemplates/dynamicfee.js +0 -192
- package/dist/cjs/logicTemplates/dynamicfee.js.map +0 -1
- package/dist/cjs/logicTemplates/htlc.js +0 -145
- package/dist/cjs/logicTemplates/htlc.js.map +0 -1
- package/dist/cjs/logicTemplates/index.js +0 -19
- package/dist/cjs/logicTemplates/index.js.map +0 -1
- package/dist/cjs/logicTemplates/limitorder.js +0 -167
- package/dist/cjs/logicTemplates/limitorder.js.map +0 -1
- package/dist/cjs/logicTemplates/periodicpayment.js +0 -163
- package/dist/cjs/logicTemplates/periodicpayment.js.map +0 -1
- package/dist/cjs/logicTemplates/split.js +0 -154
- package/dist/cjs/logicTemplates/split.js.map +0 -1
- package/dist/cjs/logicTemplates/templates.js +0 -67
- package/dist/cjs/logicTemplates/templates.js.map +0 -1
- package/dist/esm/client/algod.js +0 -295
- package/dist/esm/client/algod.js.map +0 -1
- package/dist/esm/logic/langspec.json +0 -2014
- package/dist/esm/logic/logic.js +0 -249
- package/dist/esm/logic/logic.js.map +0 -1
- package/dist/esm/logicTemplates/dynamicfee.js +0 -192
- package/dist/esm/logicTemplates/dynamicfee.js.map +0 -1
- package/dist/esm/logicTemplates/htlc.js +0 -145
- package/dist/esm/logicTemplates/htlc.js.map +0 -1
- package/dist/esm/logicTemplates/index.js +0 -19
- package/dist/esm/logicTemplates/index.js.map +0 -1
- package/dist/esm/logicTemplates/limitorder.js +0 -167
- package/dist/esm/logicTemplates/limitorder.js.map +0 -1
- package/dist/esm/logicTemplates/periodicpayment.js +0 -163
- package/dist/esm/logicTemplates/periodicpayment.js.map +0 -1
- package/dist/esm/logicTemplates/split.js +0 -154
- package/dist/esm/logicTemplates/split.js.map +0 -1
- package/dist/esm/logicTemplates/templates.js +0 -67
- package/dist/esm/logicTemplates/templates.js.map +0 -1
- package/dist/types/client/algod.d.ts +0 -162
- package/dist/types/logic/logic.d.ts +0 -45
- package/dist/types/logicTemplates/dynamicfee.d.ts +0 -59
- package/dist/types/logicTemplates/htlc.d.ts +0 -51
- package/dist/types/logicTemplates/index.d.ts +0 -16
- package/dist/types/logicTemplates/limitorder.d.ts +0 -70
- package/dist/types/logicTemplates/periodicpayment.d.ts +0 -58
- package/dist/types/logicTemplates/split.d.ts +0 -57
- package/dist/types/logicTemplates/templates.d.ts +0 -6
- package/src/client/algod.js +0 -365
- package/src/logic/langspec.json +0 -2014
- package/src/logic/logic.ts +0 -316
- package/src/logicTemplates/dynamicfee.js +0 -219
- package/src/logicTemplates/htlc.js +0 -165
- package/src/logicTemplates/index.js +0 -20
- package/src/logicTemplates/limitorder.js +0 -227
- package/src/logicTemplates/periodicpayment.js +0 -208
- package/src/logicTemplates/split.js +0 -208
- package/src/logicTemplates/templates.js +0 -78
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
const address = require('../encoding/address');
|
|
2
|
-
const makeTxn = require('../makeTxn');
|
|
3
|
-
const group = require('../group');
|
|
4
|
-
const logic = require('../logic/logic');
|
|
5
|
-
const logicSig = require('../logicsig');
|
|
6
|
-
const nacl = require('../nacl/naclWrappers');
|
|
7
|
-
const templates = require('./templates');
|
|
8
|
-
const utils = require('../utils/utils');
|
|
9
|
-
class LimitOrder {
|
|
10
|
-
/**
|
|
11
|
-
* MakeLimitOrder allows a user to exchange some number of assets for some number of algos.
|
|
12
|
-
* Fund the contract with some number of Algos to limit the maximum number of
|
|
13
|
-
* Algos you're willing to trade for some other asset.
|
|
14
|
-
*
|
|
15
|
-
* Works on two cases:
|
|
16
|
-
* * trading Algos for some other asset
|
|
17
|
-
* * closing out Algos back to the originator after a timeout
|
|
18
|
-
*
|
|
19
|
-
* trade case, a 2 transaction group:
|
|
20
|
-
* gtxn[0] (this txn) Algos from Me to Other
|
|
21
|
-
* gtxn[1] asset from Other to Me
|
|
22
|
-
*
|
|
23
|
-
* We want to get _at least_ some amount of the other asset per our Algos
|
|
24
|
-
* gtxn[1].AssetAmount / gtxn[0].Amount >= N / D
|
|
25
|
-
* ===
|
|
26
|
-
* gtxn[1].AssetAmount * D >= gtxn[0].Amount * N
|
|
27
|
-
*
|
|
28
|
-
* close-out case:
|
|
29
|
-
* txn alone, close out value after timeout
|
|
30
|
-
*
|
|
31
|
-
* @deprecated This class will be removed in v2.
|
|
32
|
-
*
|
|
33
|
-
* Constructor Parameters:
|
|
34
|
-
* @param {string} owner: the address to refund funds to on timeout
|
|
35
|
-
* @param {int} assetid: the ID of the transferred asset
|
|
36
|
-
* @param {int} ratn: exchange rate (N asset per D Algos, or better)
|
|
37
|
-
* @param {int} ratd: exchange rate (N asset per D Algos, or better)
|
|
38
|
-
* @param {int} expiryRound: the round at which the account expires
|
|
39
|
-
* @param {int} minTrade: the minimum amount (of Algos) to be traded away
|
|
40
|
-
* @param {int} maxFee: maximum fee used by the limit order transaction
|
|
41
|
-
* @returns {LimitOrder}
|
|
42
|
-
*/
|
|
43
|
-
constructor(owner, assetid, ratn, ratd, expiryRound, minTrade, maxFee) {
|
|
44
|
-
// don't need to validate owner - it will be validated by template.insert
|
|
45
|
-
if (!Number.isSafeInteger(assetid) || assetid < 0)
|
|
46
|
-
throw Error('assetid must be a positive number and smaller than 2^53-1');
|
|
47
|
-
if (!Number.isSafeInteger(ratn) || ratn < 0)
|
|
48
|
-
throw Error('ratn must be a positive number and smaller than 2^53-1');
|
|
49
|
-
if (!Number.isSafeInteger(ratd) || ratd < 0)
|
|
50
|
-
throw Error('ratd must be a positive number and smaller than 2^53-1');
|
|
51
|
-
if (!Number.isSafeInteger(expiryRound) || expiryRound < 0)
|
|
52
|
-
throw Error('expiryRound must be a positive number and smaller than 2^53-1');
|
|
53
|
-
if (!Number.isSafeInteger(minTrade) || minTrade < 0)
|
|
54
|
-
throw Error('minTrade must be a positive number and smaller than 2^53-1');
|
|
55
|
-
if (!Number.isSafeInteger(maxFee) || maxFee < 0)
|
|
56
|
-
throw Error('maxFee must be a positive number and smaller than 2^53-1');
|
|
57
|
-
const referenceProgramB64 = 'ASAKAAEFAgYEBwgJCiYBIP68oLsUSlpOp7Q4pGgayA5soQW8tgf8VlMlyVaV9qITMRYiEjEQIxIQMQEkDhAyBCMSQABVMgQlEjEIIQQNEDEJMgMSEDMBECEFEhAzAREhBhIQMwEUKBIQMwETMgMSEDMBEiEHHTUCNQExCCEIHTUENQM0ATQDDUAAJDQBNAMSNAI0BA8QQAAWADEJKBIxAiEJDRAxBzIDEhAxCCISEBA=';
|
|
58
|
-
const referenceProgramBytes = Buffer.from(referenceProgramB64, 'base64');
|
|
59
|
-
const referenceOffsets = [
|
|
60
|
-
5 /* minTrade */,
|
|
61
|
-
7 /* assetID */,
|
|
62
|
-
9 /* ratd */,
|
|
63
|
-
10 /* ratn */,
|
|
64
|
-
11 /* expiryRound */,
|
|
65
|
-
12 /* owner */,
|
|
66
|
-
16,
|
|
67
|
-
];
|
|
68
|
-
const injectionVector = [
|
|
69
|
-
maxFee,
|
|
70
|
-
minTrade,
|
|
71
|
-
assetid,
|
|
72
|
-
ratd,
|
|
73
|
-
ratn,
|
|
74
|
-
expiryRound,
|
|
75
|
-
owner,
|
|
76
|
-
];
|
|
77
|
-
const injectionTypes = [
|
|
78
|
-
templates.valTypes.INT,
|
|
79
|
-
templates.valTypes.INT,
|
|
80
|
-
templates.valTypes.INT,
|
|
81
|
-
templates.valTypes.INT,
|
|
82
|
-
templates.valTypes.INT,
|
|
83
|
-
templates.valTypes.INT,
|
|
84
|
-
templates.valTypes.ADDRESS,
|
|
85
|
-
];
|
|
86
|
-
const injectedBytes = templates.inject(referenceProgramBytes, referenceOffsets, injectionVector, injectionTypes);
|
|
87
|
-
this.programBytes = injectedBytes;
|
|
88
|
-
const lsig = new logicSig.LogicSig(injectedBytes, undefined);
|
|
89
|
-
this.address = lsig.address();
|
|
90
|
-
this.owner = owner;
|
|
91
|
-
this.assetid = assetid;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* returns the program bytes
|
|
95
|
-
* @returns {Uint8Array}
|
|
96
|
-
*/
|
|
97
|
-
getProgram() {
|
|
98
|
-
return this.programBytes;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* returns the string address of the contract
|
|
102
|
-
* @returns {string}
|
|
103
|
-
*/
|
|
104
|
-
getAddress() {
|
|
105
|
-
return this.address;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* returns a group transactions array which transfer funds according to the contract's ratio
|
|
110
|
-
*
|
|
111
|
-
* @deprecated This feature will be removed in v2.
|
|
112
|
-
*
|
|
113
|
-
* @param {Uint8Array} contract: byteform of the contract from the payer
|
|
114
|
-
* @param {int} assetAmount: the amount of assets to be sent
|
|
115
|
-
* @param {int} microAlgoAmount: number of microAlgos to transfer
|
|
116
|
-
* @param {Uint8Array} secretKey: secret key for signing transaction
|
|
117
|
-
* @param {int} fee: the fee per byte to pay in microAlgos
|
|
118
|
-
* @param {int} firstRound: the first round on which these txns will be valid
|
|
119
|
-
* @param {int} lastRound: the last round on which these txns will be valid
|
|
120
|
-
* @param {string} genesisHash: the b64-encoded genesis hash indicating the network for this transaction
|
|
121
|
-
* @returns {Uint8Array}
|
|
122
|
-
* the first payment sends money (Algos) from contract to the recipient (we'll call him Buyer), closing the rest of the account to Owner
|
|
123
|
-
* the second payment sends money (the asset) from Buyer to the Owner
|
|
124
|
-
* these transactions will be rejected if they do not meet the restrictions set by the contract
|
|
125
|
-
* @throws error if arguments fail contract validation
|
|
126
|
-
*/
|
|
127
|
-
function getSwapAssetsTransaction(contract, assetAmount, microAlgoAmount, secretKey, fee, firstRound, lastRound, genesisHash) {
|
|
128
|
-
const buyerKeyPair = nacl.keyPairFromSecretKey(secretKey);
|
|
129
|
-
const buyerAddr = address.encodeAddress(buyerKeyPair.publicKey);
|
|
130
|
-
const programOutputs = logic.readProgram(contract, undefined);
|
|
131
|
-
const ints = programOutputs[0];
|
|
132
|
-
const byteArrays = programOutputs[1];
|
|
133
|
-
let noCloseRemainder;
|
|
134
|
-
let noAssetRevocationTarget;
|
|
135
|
-
const contractAssetID = ints[6];
|
|
136
|
-
const contractOwner = address.encodeAddress(byteArrays[0]);
|
|
137
|
-
const lsig = logicSig.makeLogicSig(contract, undefined);
|
|
138
|
-
const contractAddress = lsig.address();
|
|
139
|
-
const algosForAssets = makeTxn.makePaymentTxn(contractAddress, buyerAddr, fee, microAlgoAmount, noCloseRemainder, firstRound, lastRound, undefined, genesisHash, undefined);
|
|
140
|
-
const assetsForAlgos = makeTxn.makeAssetTransferTxn(buyerAddr, contractOwner, noCloseRemainder, noAssetRevocationTarget, fee, assetAmount, firstRound, lastRound, undefined, genesisHash, undefined, contractAssetID);
|
|
141
|
-
const txns = [algosForAssets, assetsForAlgos];
|
|
142
|
-
const txGroup = group.assignGroupID(txns);
|
|
143
|
-
const ratd = ints[7];
|
|
144
|
-
const ratn = ints[8];
|
|
145
|
-
if (assetAmount * ratd < microAlgoAmount * ratn) {
|
|
146
|
-
throw new Error(`bad payment ratio, ${assetAmount.toString()}*${ratd.toString()} !>= ${microAlgoAmount.toString()}*${ratn.toString()}`);
|
|
147
|
-
}
|
|
148
|
-
const minTrade = ints[4];
|
|
149
|
-
if (microAlgoAmount < minTrade) {
|
|
150
|
-
throw new Error(`payment amount ${microAlgoAmount.toString()} less than minimum trade ${minTrade.toString()}`);
|
|
151
|
-
}
|
|
152
|
-
const maxFee = ints[2];
|
|
153
|
-
if (txGroup[0].fee > maxFee) {
|
|
154
|
-
throw new Error(`final fee of payment transaction ${txGroup[0].fee.toString()} greater than transaction max fee ${maxFee.toString()}`);
|
|
155
|
-
}
|
|
156
|
-
if (txGroup[1].fee > maxFee) {
|
|
157
|
-
throw new Error(`final fee of asset transaction ${txGroup[1].fee.toString()} greater than transaction max fee ${maxFee.toString()}`);
|
|
158
|
-
}
|
|
159
|
-
const algosForAssetsSigned = logicSig.signLogicSigTransactionObject(txGroup[0], lsig);
|
|
160
|
-
const assetsForAlgosSigned = txGroup[1].signTxn(secretKey);
|
|
161
|
-
return utils.concatArrays(algosForAssetsSigned.blob, assetsForAlgosSigned);
|
|
162
|
-
}
|
|
163
|
-
module.exports = {
|
|
164
|
-
LimitOrder,
|
|
165
|
-
getSwapAssetsTransaction,
|
|
166
|
-
};
|
|
167
|
-
//# sourceMappingURL=limitorder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"limitorder.js","sourceRoot":"","sources":["../../../src/logicTemplates/limitorder.js"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AACtC,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAClC,MAAM,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACxC,MAAM,IAAI,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC7C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACzC,MAAM,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAExC,MAAM,UAAU;IACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,YAAY,KAAK,EAAE,O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CAAC,QAAQ,EAAE,EAAE,CACvH,CAAC;KACH;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,eAAe,GAAG,QAAQ,EAAE;QAC9B,MAAM,IAAI,KAAK,CACb,kBAAkB,eAAe,CAAC,QAAQ,EAAE,4BAA4B,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAC9F,CAAC;KACH;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,oCAAoC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,qCAAqC,MAAM,CAAC,QAAQ,EAAE,EAAE,CACtH,CAAC;KACH;IACD,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,qCAAqC,MAAM,CAAC,QAAQ,EAAE,EAAE,CACpH,CAAC;KACH;IAED,MAAM,oBAAoB,GAAG,QAAQ,CAAC,6BAA6B,CACjE,OAAO,CAAC,CAAC,CAAC,EACV,IAAI,CACL,CAAC;IACF,MAAM,oBAAoB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC,YAAY,CAAC,oBAAoB,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,UAAU;IACV,wBAAwB;CACzB,CAAC"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
const address = require('../encoding/address');
|
|
2
|
-
const makeTxn = require('../makeTxn');
|
|
3
|
-
const logic = require('../logic/logic');
|
|
4
|
-
const logicSig = require('../logicsig');
|
|
5
|
-
const nacl = require('../nacl/naclWrappers');
|
|
6
|
-
const templates = require('./templates');
|
|
7
|
-
class PeriodicPayment {
|
|
8
|
-
/**
|
|
9
|
-
* MakePeriodicPayment allows some account to execute periodic withdrawal of funds.
|
|
10
|
-
* This is a contract account.
|
|
11
|
-
*
|
|
12
|
-
* This allows receiver to withdraw amount every
|
|
13
|
-
* period rounds for withdrawWindow after every multiple
|
|
14
|
-
* of period.
|
|
15
|
-
*
|
|
16
|
-
* After expiryRound, all remaining funds in the escrow
|
|
17
|
-
* are available to receiver.
|
|
18
|
-
*
|
|
19
|
-
* @deprecated This class will be removed in v2.
|
|
20
|
-
*
|
|
21
|
-
* Constructor Parameters:
|
|
22
|
-
* @param {string} receiver: address which is authorized to receive withdrawals
|
|
23
|
-
* @param {int} amount: the amount to send each period
|
|
24
|
-
* @param {int} withdrawalWindow: the duration of a withdrawal period
|
|
25
|
-
* @param {int} period: the time between a pair of withdrawal periods
|
|
26
|
-
* @param {int} expiryRound: the round at which the account expires
|
|
27
|
-
* @param {int} maxFee: maximum fee used by the withdrawal transaction
|
|
28
|
-
* @param {string} lease: b64 representation of lease to use, or leave undefined to generate one
|
|
29
|
-
* @returns {PeriodicPayment}
|
|
30
|
-
*/
|
|
31
|
-
constructor(receiver, amount, withdrawalWindow, period, expiryRound, maxFee, lease) {
|
|
32
|
-
// don't need to validate receiver or lease, it's validated by template insert
|
|
33
|
-
this.receiver = receiver;
|
|
34
|
-
if (!Number.isSafeInteger(amount) || amount < 0)
|
|
35
|
-
throw Error('amount must be a positive number and smaller than 2^53-1');
|
|
36
|
-
this.amount = amount;
|
|
37
|
-
if (!Number.isSafeInteger(withdrawalWindow) || withdrawalWindow < 0)
|
|
38
|
-
throw Error('withdrawalWindow must be a positive number and smaller than 2^53-1');
|
|
39
|
-
this.withdrawalWindow = withdrawalWindow;
|
|
40
|
-
if (!Number.isSafeInteger(period) || period < 0)
|
|
41
|
-
throw Error('period must be a positive number and smaller than 2^53-1');
|
|
42
|
-
this.period = period;
|
|
43
|
-
if (!Number.isSafeInteger(expiryRound) || expiryRound < 0)
|
|
44
|
-
throw Error('expiryRound must be a positive number and smaller than 2^53-1');
|
|
45
|
-
this.expiryRound = expiryRound;
|
|
46
|
-
if (!Number.isSafeInteger(maxFee) || maxFee < 0)
|
|
47
|
-
throw Error('maxFee must be a positive number and smaller than 2^53-1');
|
|
48
|
-
this.maxFee = maxFee;
|
|
49
|
-
if (lease === undefined) {
|
|
50
|
-
const leaseBytes = nacl.randomBytes(32);
|
|
51
|
-
this.lease = Buffer.from(leaseBytes).toString('base64');
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
this.lease = lease;
|
|
55
|
-
}
|
|
56
|
-
this.programBytes = this.getProgram();
|
|
57
|
-
const lsig = new logicSig.LogicSig(this.programBytes, undefined);
|
|
58
|
-
this.address = lsig.address();
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* returns the program bytes
|
|
62
|
-
* @returns {Uint8Array}
|
|
63
|
-
*/
|
|
64
|
-
getProgram() {
|
|
65
|
-
const referenceProgramB64 = 'ASAHAQYFAAQDByYCIAECAwQFBgcIAQIDBAUGBwgBAgMEBQYHCAECAwQFBgcIIJKvkYTkEzwJf2arzJOxERsSogG9nQzKPkpIoc4TzPTFMRAiEjEBIw4QMQIkGCUSEDEEIQQxAggSEDEGKBIQMQkyAxIxBykSEDEIIQUSEDEJKRIxBzIDEhAxAiEGDRAxCCUSEBEQ';
|
|
66
|
-
const referenceProgramBytes = Buffer.from(referenceProgramB64, 'base64');
|
|
67
|
-
const referenceOffsets = [
|
|
68
|
-
4 /* period */,
|
|
69
|
-
5 /* withdrawWindow */,
|
|
70
|
-
7 /* amount */,
|
|
71
|
-
8 /* expiryRound */,
|
|
72
|
-
9 /* lease */,
|
|
73
|
-
12 /* receiver */,
|
|
74
|
-
46,
|
|
75
|
-
];
|
|
76
|
-
const injectionVector = [
|
|
77
|
-
this.maxFee,
|
|
78
|
-
this.period,
|
|
79
|
-
this.withdrawalWindow,
|
|
80
|
-
this.amount,
|
|
81
|
-
this.expiryRound,
|
|
82
|
-
this.lease,
|
|
83
|
-
this.receiver,
|
|
84
|
-
];
|
|
85
|
-
const injectionTypes = [
|
|
86
|
-
templates.valTypes.INT,
|
|
87
|
-
templates.valTypes.INT,
|
|
88
|
-
templates.valTypes.INT,
|
|
89
|
-
templates.valTypes.INT,
|
|
90
|
-
templates.valTypes.INT,
|
|
91
|
-
templates.valTypes.BASE64,
|
|
92
|
-
templates.valTypes.ADDRESS,
|
|
93
|
-
];
|
|
94
|
-
return templates.inject(referenceProgramBytes, referenceOffsets, injectionVector, injectionTypes);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* returns the string address of the contract
|
|
98
|
-
* @returns {string}
|
|
99
|
-
*/
|
|
100
|
-
getAddress() {
|
|
101
|
-
return this.address;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* getPeriodicPaymentWithdrawalTransaction returns a signed transaction extracting funds form the contract
|
|
106
|
-
*
|
|
107
|
-
* @deprecated This feature will be removed in v2.
|
|
108
|
-
*
|
|
109
|
-
* @param {Uint8Array} contract: the bytearray defining the contract, received from the payer
|
|
110
|
-
* @param {int} fee: the fee per byte for the transaction
|
|
111
|
-
* @param {int} firstValid: the first round on which the txn will be valid
|
|
112
|
-
* @param {string} genesisHash: the hash representing the network for the txn
|
|
113
|
-
* @returns {Object} Object containing txID and blob representing signed transaction
|
|
114
|
-
* @throws error on failure
|
|
115
|
-
*/
|
|
116
|
-
function getPeriodicPaymentWithdrawalTransaction(contract, fee, firstValid, genesisHash) {
|
|
117
|
-
const readResult = logic.readProgram(contract, undefined);
|
|
118
|
-
const ints = readResult[0];
|
|
119
|
-
const byteArrays = readResult[1];
|
|
120
|
-
const period = ints[2];
|
|
121
|
-
const duration = ints[4];
|
|
122
|
-
const amount = ints[5];
|
|
123
|
-
if (firstValid % period !== 0) {
|
|
124
|
-
throw new Error(`firstValid round ${firstValid.toString()} was not a multiple of contract period ${period.toString()}`);
|
|
125
|
-
}
|
|
126
|
-
// extract receiver and convert as needed
|
|
127
|
-
const receiverBytes = byteArrays[1];
|
|
128
|
-
const receiver = address.encodeAddress(receiverBytes);
|
|
129
|
-
// extract lease and convert
|
|
130
|
-
const leaseBuffer = byteArrays[0];
|
|
131
|
-
const lease = new Uint8Array(leaseBuffer);
|
|
132
|
-
const lastValid = firstValid + duration;
|
|
133
|
-
const to = receiver;
|
|
134
|
-
let noCloseRemainder;
|
|
135
|
-
let noNote;
|
|
136
|
-
const lsig = logicSig.makeLogicSig(contract, undefined);
|
|
137
|
-
const from = lsig.address();
|
|
138
|
-
const txn = {
|
|
139
|
-
from,
|
|
140
|
-
to,
|
|
141
|
-
fee,
|
|
142
|
-
amount,
|
|
143
|
-
closeRemainderTo: noCloseRemainder,
|
|
144
|
-
firstRound: firstValid,
|
|
145
|
-
lastRound: lastValid,
|
|
146
|
-
note: noNote,
|
|
147
|
-
genesisHash,
|
|
148
|
-
genesisID: '',
|
|
149
|
-
type: 'pay',
|
|
150
|
-
lease,
|
|
151
|
-
};
|
|
152
|
-
// check fee
|
|
153
|
-
const tempTxn = makeTxn.makePaymentTxn(from, to, fee, amount, noCloseRemainder, firstValid, lastValid, noNote, genesisHash, '');
|
|
154
|
-
if (tempTxn.fee > ints[1]) {
|
|
155
|
-
throw new Error(`final fee of payment transaction${tempTxn.fee.toString()}greater than transaction max fee${ints[1].toString()}`);
|
|
156
|
-
}
|
|
157
|
-
return logicSig.signLogicSigTransaction(txn, lsig);
|
|
158
|
-
}
|
|
159
|
-
module.exports = {
|
|
160
|
-
PeriodicPayment,
|
|
161
|
-
getPeriodicPaymentWithdrawalTransaction,
|
|
162
|
-
};
|
|
163
|
-
//# sourceMappingURL=periodicpayment.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"periodicpayment.js","sourceRoot":"","sources":["../../../src/logicTemplates/periodicpayment.js"],"names":[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|
|
3
|
-
const group = require('../group');
|
|
4
|
-
const logicsig = require('../logicsig');
|
|
5
|
-
const logic = require('../logic/logic');
|
|
6
|
-
const templates = require('./templates');
|
|
7
|
-
const utils = require('../utils/utils');
|
|
8
|
-
class Split {
|
|
9
|
-
/**
|
|
10
|
-
* Split splits money sent to some account to two recipients at some ratio.
|
|
11
|
-
* This is a contract account.
|
|
12
|
-
*
|
|
13
|
-
* This allows either a two-transaction group, for executing a
|
|
14
|
-
* split, or single transaction, for closing the account.
|
|
15
|
-
*
|
|
16
|
-
* Withdrawals from this account are allowed as a group transaction which
|
|
17
|
-
* sends receiverOne and receiverTwo amounts with exactly the specified ratio:
|
|
18
|
-
* (rat1*amountForReceiverOne) = (rat2*amountForReceiverTwo)
|
|
19
|
-
* At least minPay must be sent to receiverOne.
|
|
20
|
-
* (CloseRemainderTo must be zero.)
|
|
21
|
-
*
|
|
22
|
-
* After expiryRound passes, all funds can be refunded to owner.
|
|
23
|
-
*
|
|
24
|
-
* @deprecated This feature will be removed in v2.
|
|
25
|
-
*
|
|
26
|
-
* Constructor Parameters:
|
|
27
|
-
* @param {string} owner: the address to refund funds to on timeout
|
|
28
|
-
* @param {string} receiverOne: the first recipient in the split account
|
|
29
|
-
* @param {string} receiverTwo: the second recipient in the split account
|
|
30
|
-
* @param {int} rat1: fraction of money to be paid to the 1st recipient
|
|
31
|
-
* @param {int} rat2: fraction of money to be paid to the 2nd recipient
|
|
32
|
-
* @param {int} expiryRound: the round at which the account expires
|
|
33
|
-
* @param {int} minPay: minimum amount to be paid out of the account
|
|
34
|
-
* @param {int} maxFee: half of the maximum fee used by each split forwarding group transaction
|
|
35
|
-
* @returns {Split}
|
|
36
|
-
*/
|
|
37
|
-
constructor(owner, receiverOne, receiverTwo, rat1, rat2, expiryRound, minPay, maxFee) {
|
|
38
|
-
// don't need to validate owner, receiverone, receivertwo - they'll be validated by template.insert
|
|
39
|
-
if (!Number.isSafeInteger(rat2) || rat2 < 0)
|
|
40
|
-
throw Error('rat2 must be a positive number and smaller than 2^53-1');
|
|
41
|
-
if (!Number.isSafeInteger(rat1) || rat1 < 0)
|
|
42
|
-
throw Error('rat1 must be a positive number and smaller than 2^53-1');
|
|
43
|
-
if (!Number.isSafeInteger(expiryRound) || expiryRound < 0)
|
|
44
|
-
throw Error('expiryRound must be a positive number and smaller than 2^53-1');
|
|
45
|
-
if (!Number.isSafeInteger(minPay) || minPay < 0)
|
|
46
|
-
throw Error('minPay must be a positive number and smaller than 2^53-1');
|
|
47
|
-
if (!Number.isSafeInteger(maxFee) || maxFee < 0)
|
|
48
|
-
throw Error('maxFee must be a positive number and smaller than 2^53-1');
|
|
49
|
-
const referenceProgramB64 = 'ASAIAQUCAAYHCAkmAyCztwQn0+DycN+vsk+vJWcsoz/b7NDS6i33HOkvTpf+YiC3qUpIgHGWE8/1LPh9SGCalSN7IaITeeWSXbfsS5wsXyC4kBQ38Z8zcwWVAym4S8vpFB/c0XC6R4mnPi9EBADsPDEQIhIxASMMEDIEJBJAABkxCSgSMQcyAxIQMQglEhAxAiEEDRAiQAAuMwAAMwEAEjEJMgMSEDMABykSEDMBByoSEDMACCEFCzMBCCEGCxIQMwAIIQcPEBA=';
|
|
50
|
-
const referenceProgramBytes = Buffer.from(referenceProgramB64, 'base64');
|
|
51
|
-
const referenceOffsets = [
|
|
52
|
-
4 /* timeout */,
|
|
53
|
-
7 /* rat2 */,
|
|
54
|
-
8 /* rat1 */,
|
|
55
|
-
9 /* minPay */,
|
|
56
|
-
10 /* owner */,
|
|
57
|
-
14 /* receiver1 */,
|
|
58
|
-
47 /* receiver2 */,
|
|
59
|
-
80,
|
|
60
|
-
];
|
|
61
|
-
const injectionVector = [
|
|
62
|
-
maxFee,
|
|
63
|
-
expiryRound,
|
|
64
|
-
rat2,
|
|
65
|
-
rat1,
|
|
66
|
-
minPay,
|
|
67
|
-
owner,
|
|
68
|
-
receiverOne,
|
|
69
|
-
receiverTwo,
|
|
70
|
-
];
|
|
71
|
-
const injectionTypes = [
|
|
72
|
-
templates.valTypes.INT,
|
|
73
|
-
templates.valTypes.INT,
|
|
74
|
-
templates.valTypes.INT,
|
|
75
|
-
templates.valTypes.INT,
|
|
76
|
-
templates.valTypes.INT,
|
|
77
|
-
templates.valTypes.ADDRESS,
|
|
78
|
-
templates.valTypes.ADDRESS,
|
|
79
|
-
templates.valTypes.ADDRESS,
|
|
80
|
-
];
|
|
81
|
-
const injectedBytes = templates.inject(referenceProgramBytes, referenceOffsets, injectionVector, injectionTypes);
|
|
82
|
-
this.programBytes = injectedBytes;
|
|
83
|
-
const lsig = logicsig.makeLogicSig(injectedBytes, undefined);
|
|
84
|
-
this.address = lsig.address();
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* returns the program bytes
|
|
88
|
-
* @returns {Uint8Array}
|
|
89
|
-
*/
|
|
90
|
-
getProgram() {
|
|
91
|
-
return this.programBytes;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* returns the string address of the contract
|
|
95
|
-
* @returns {string}
|
|
96
|
-
*/
|
|
97
|
-
getAddress() {
|
|
98
|
-
return this.address;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* returns a group transactions array which transfer funds according to the contract's ratio
|
|
103
|
-
*
|
|
104
|
-
* @deprecated This feature will be removed in v2.
|
|
105
|
-
*
|
|
106
|
-
* @param {Uint8Array} contract: bytes representing the contract in question
|
|
107
|
-
* @param {int} amount: the amount to be transferred
|
|
108
|
-
* @param {int} firstRound: the first round on which the transaction group will be valid
|
|
109
|
-
* @param {int} lastRound: the last round on which the transaction group will be valid
|
|
110
|
-
* @param {int} fee: the fee to pay in microAlgos
|
|
111
|
-
* @param {string} genesisHash: the b64-encoded genesis hash indicating the network for this transaction
|
|
112
|
-
* @returns {Uint8Array}
|
|
113
|
-
*/
|
|
114
|
-
function getSplitFundsTransaction(contract, amount, firstRound, lastRound, fee, genesisHash) {
|
|
115
|
-
const programOutputs = logic.readProgram(contract, undefined);
|
|
116
|
-
const ints = programOutputs[0];
|
|
117
|
-
const byteArrays = programOutputs[1];
|
|
118
|
-
let rat2 = ints[6];
|
|
119
|
-
let rat1 = ints[5];
|
|
120
|
-
let amountForReceiverOne = 0;
|
|
121
|
-
// reduce fractions
|
|
122
|
-
const gcdFn = (a, b) => {
|
|
123
|
-
if (typeof a !== 'number' || typeof b !== 'number')
|
|
124
|
-
throw new Error('gcd operates only on positive integers');
|
|
125
|
-
if (!b) {
|
|
126
|
-
return a;
|
|
127
|
-
}
|
|
128
|
-
return gcdFn(b, a % b);
|
|
129
|
-
};
|
|
130
|
-
const gcd = gcdFn(rat2, rat1);
|
|
131
|
-
rat2 = Math.floor(rat2 / gcd);
|
|
132
|
-
rat1 = Math.floor(rat1 / gcd);
|
|
133
|
-
const ratio = rat1 / rat2;
|
|
134
|
-
amountForReceiverOne = Math.round(amount / (1 + ratio));
|
|
135
|
-
const amountForReceiverTwo = amount - amountForReceiverOne;
|
|
136
|
-
if (rat1 * amountForReceiverOne !== rat2 * amountForReceiverTwo) {
|
|
137
|
-
throw Error('could not split funds in a way that satisfied the contract ratio');
|
|
138
|
-
}
|
|
139
|
-
const logicSig = logicsig.makeLogicSig(contract, undefined); // no args
|
|
140
|
-
const from = logicSig.address();
|
|
141
|
-
const receiverOne = address.encodeAddress(byteArrays[1]);
|
|
142
|
-
const receiverTwo = address.encodeAddress(byteArrays[2]);
|
|
143
|
-
const tx1 = makeTxn.makePaymentTxn(from, receiverOne, fee, amountForReceiverOne, undefined, firstRound, lastRound, undefined, genesisHash);
|
|
144
|
-
const tx2 = makeTxn.makePaymentTxn(from, receiverTwo, fee, amountForReceiverTwo, undefined, firstRound, lastRound, undefined, genesisHash);
|
|
145
|
-
const txns = [tx1, tx2];
|
|
146
|
-
const txGroup = group.assignGroupID(txns);
|
|
147
|
-
const signedTxns = txGroup.map((txn) => logicsig.signLogicSigTransactionObject(txn, logicsig).blob);
|
|
148
|
-
return utils.concatArrays(signedTxns[0], signedTxns[1]);
|
|
149
|
-
}
|
|
150
|
-
module.exports = {
|
|
151
|
-
Split,
|
|
152
|
-
getSplitFundsTransaction,
|
|
153
|
-
};
|
|
154
|
-
//# sourceMappingURL=split.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../../src/logicTemplates/split.js"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AACtC,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACxC,MAAM,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACxC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACzC,MAAM,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAExC,MAAM,KAAK;IACT;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,YACE,KAAK,EACL,WAAW,EACX,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,MAAM,EACN,MAAM;QAEN,mGAAmG;QACnG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC;YACzC,MAAM,KAAK,CAAC,wDAAwD,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC;YACzC,MAAM,KAAK,CAAC,wDAAwD,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,WAAW,GAAG,CAAC;YACvD,MAAM,KAAK,CACT,+DAA+D,CAChE,CAAC;QACJ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC;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AAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,KAAK;IACL,wBAAwB;CACzB,CAAC"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-bitwise */
|
|
2
|
-
const address = require('../encoding/address');
|
|
3
|
-
function putUvarint(buf, x) {
|
|
4
|
-
let i = 0;
|
|
5
|
-
while (x > 0x80) {
|
|
6
|
-
buf.push((x & 0xff) | 0x80);
|
|
7
|
-
// eslint-disable-next-line no-param-reassign
|
|
8
|
-
x >>= 7;
|
|
9
|
-
i += 1;
|
|
10
|
-
}
|
|
11
|
-
buf.push(x & 0xff);
|
|
12
|
-
return i + 1;
|
|
13
|
-
}
|
|
14
|
-
const valTypes = {
|
|
15
|
-
INT: 1,
|
|
16
|
-
ADDRESS: 2,
|
|
17
|
-
BASE64: 3,
|
|
18
|
-
};
|
|
19
|
-
function inject(orig, offsets, values, valueTypes) {
|
|
20
|
-
if (offsets.length !== values.length ||
|
|
21
|
-
offsets.length !== valueTypes.length) {
|
|
22
|
-
throw new Error('Lengths do not match');
|
|
23
|
-
}
|
|
24
|
-
let res = orig;
|
|
25
|
-
function replace(arr, newVal, offset, placeholderLength) {
|
|
26
|
-
const beforeReplacement = arr.slice(0, offset);
|
|
27
|
-
const afterReplacement = arr.slice(offset + placeholderLength, arr.length);
|
|
28
|
-
const chunks = [beforeReplacement, Buffer.from(newVal), afterReplacement];
|
|
29
|
-
return Buffer.concat(chunks);
|
|
30
|
-
}
|
|
31
|
-
for (let i = 0; i < offsets.length; i++) {
|
|
32
|
-
let decodedLength = 0;
|
|
33
|
-
let val = values[i];
|
|
34
|
-
const valType = valueTypes[i];
|
|
35
|
-
switch (valType) {
|
|
36
|
-
case valTypes.INT:
|
|
37
|
-
// eslint-disable-next-line no-case-declarations
|
|
38
|
-
const intBuf = [];
|
|
39
|
-
decodedLength = putUvarint(intBuf, val);
|
|
40
|
-
res = replace(res, intBuf, offsets[i], 1);
|
|
41
|
-
break;
|
|
42
|
-
case valTypes.ADDRESS:
|
|
43
|
-
val = address.decodeAddress(val);
|
|
44
|
-
res = replace(res, val.publicKey, offsets[i], 32);
|
|
45
|
-
break;
|
|
46
|
-
case valTypes.BASE64:
|
|
47
|
-
// eslint-disable-next-line no-case-declarations
|
|
48
|
-
const lenBuf = [];
|
|
49
|
-
val = Buffer.from(val, 'base64');
|
|
50
|
-
putUvarint(lenBuf, val.length);
|
|
51
|
-
val = Buffer.concat([Buffer.from(lenBuf), val]);
|
|
52
|
-
res = replace(res, val, offsets[i], 33);
|
|
53
|
-
break;
|
|
54
|
-
default:
|
|
55
|
-
throw new Error('unrecognized value type');
|
|
56
|
-
}
|
|
57
|
-
if (decodedLength !== 0) {
|
|
58
|
-
for (let o = 0; o < offsets.length; o++) {
|
|
59
|
-
// eslint-disable-next-line no-param-reassign
|
|
60
|
-
offsets[o] += decodedLength - 1;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return res;
|
|
65
|
-
}
|
|
66
|
-
module.exports = { inject, valTypes };
|
|
67
|
-
//# sourceMappingURL=templates.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/logicTemplates/templates.js"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAE/C,SAAS,UAAU,CAAC,GAAG,EAAE,CAAC;IACxB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,IAAI,EAAE;QACf,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC5B,6CAA6C;QAC7C,CAAC,KAAK,CAAC,CAAC;QACR,CAAC,IAAI,CAAC,CAAC;KACR;IACD,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,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