Skip to content

Commit 36a279f

Browse files
authored
Merge pull request #111 from tinymanorg/fix/tiny-2006-fix-apply-rate-change
Liquid Restake - Fix applyRateChange txn params
2 parents a5c77e7 + be2fb28 commit 36a279f

File tree

7 files changed

+16
-36
lines changed

7 files changed

+16
-36
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/order/utils.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { joinByteArrays } from "../util/util";
21
declare function createPaddedByteArray(elements: number[], length?: number, paddingValue?: number, byteSize?: number): Uint8Array;
3-
declare function computeSHA512(fileArrayBuffer: Uint8Array): Promise<string>;
42
declare function getCompiledPrograms(): Promise<{
53
approvalProgram: Uint8Array;
64
clearProgram: Uint8Array;
75
}>;
8-
export { computeSHA512, createPaddedByteArray, getCompiledPrograms, joinByteArrays };
6+
export { createPaddedByteArray, getCompiledPrograms };

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tinymanorg/tinyman-js-sdk",
3-
"version": "5.1.1",
3+
"version": "5.1.2",
44
"description": "Tinyman JS SDK",
55
"author": "Tinyman Core Team",
66
"license": "MIT",

src/liquid-stake/stAlgoClient.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TinymanSTAlgoClient extends TinymanBaseClient<number, algosdk.Address> {
3333
const userStateBoxName = this.getUserStateBoxName(userAddress);
3434

3535
const txns = [
36-
...(await this.getApplyRateChangeTxnIfNeeded()),
36+
...(await this.getApplyRateChangeTxnIfNeeded(userAddress)),
3737
...(await this.getUserBoxPaymentTxnIfNeeded(userAddress, suggestedParams)),
3838
...(await this.getOptinTxnIfNeeded(userAddress, STALGO_ASSET_ID[this.network])),
3939
algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
@@ -70,7 +70,7 @@ class TinymanSTAlgoClient extends TinymanBaseClient<number, algosdk.Address> {
7070
const userStateBoxName = this.getUserStateBoxName(userAddress);
7171

7272
const txns = [
73-
...(await this.getApplyRateChangeTxnIfNeeded()),
73+
...(await this.getApplyRateChangeTxnIfNeeded(userAddress)),
7474
...(await this.getOptinTxnIfNeeded(userAddress, TALGO_ASSET_ID[this.network])),
7575
algosdk.makeApplicationNoOpTxnFromObject({
7676
sender: userAddress,
@@ -90,7 +90,7 @@ class TinymanSTAlgoClient extends TinymanBaseClient<number, algosdk.Address> {
9090
const userStateBoxName = this.getUserStateBoxName(userAddress);
9191

9292
const txns = [
93-
...(await this.getApplyRateChangeTxnIfNeeded()),
93+
...(await this.getApplyRateChangeTxnIfNeeded(userAddress)),
9494
...(await this.getOptinTxnIfNeeded(userAddress, TINY_ASSET_ID[this.network])),
9595
algosdk.makeApplicationNoOpTxnFromObject({
9696
sender: userAddress,
@@ -145,9 +145,9 @@ class TinymanSTAlgoClient extends TinymanBaseClient<number, algosdk.Address> {
145145
return algosdk.decodeAddress(userAddress).publicKey;
146146
}
147147

148-
private async getApplyRateChangeTxnIfNeeded() {
148+
private async getApplyRateChangeTxnIfNeeded(userAddress: string) {
149149
if (await this.shouldApplyRateChange()) {
150-
return this.getApplyRateChangeTxn();
150+
return this.getApplyRateChangeTxn(userAddress);
151151
}
152152

153153
return [];
@@ -195,17 +195,15 @@ class TinymanSTAlgoClient extends TinymanBaseClient<number, algosdk.Address> {
195195
return currentRateEndTimestamp <= now;
196196
}
197197

198-
private async getApplyRateChangeTxn() {
199-
const txns = [
198+
private async getApplyRateChangeTxn(userAddress: string) {
199+
return [
200200
algosdk.makeApplicationNoOpTxnFromObject({
201-
sender: this.applicationAddress,
201+
sender: userAddress,
202202
appIndex: this.appId,
203203
appArgs: [encodeString("apply_rate_change")],
204204
suggestedParams: await this.getSuggestedParams()
205205
})
206206
];
207-
208-
return this.setupTxnFeeAndAssignGroupId({txns});
209207
}
210208
}
211209

src/order/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
MINIMUM_BALANCE_REQUIRED_PER_BYTE_SCHEMA,
1818
MINIMUM_BALANCE_REQUIRED_PER_INT_SCHEMA_VALUE
1919
} from "../util/constant";
20-
import {encodeString, intToBytes} from "../util/util";
20+
import {encodeString, intToBytes, joinByteArrays} from "../util/util";
2121
import {
2222
APP_LATEST_VERSION_KEY,
2323
APP_VERSION_KEY,
@@ -39,7 +39,7 @@ import {
3939
PutRecurringOrderParams,
4040
PutTriggerOrderParams
4141
} from "./types";
42-
import {createPaddedByteArray, getCompiledPrograms, joinByteArrays} from "./utils";
42+
import {createPaddedByteArray, getCompiledPrograms} from "./utils";
4343

4444
const ENTRY_STRUCT = new Struct(OrderStruct.Entry, ORDER_STRUCTS);
4545
const TRIGGER_STRUCT = new Struct(OrderStruct.Trigger, ORDER_STRUCTS);
@@ -156,7 +156,6 @@ class OrderingClient extends TinymanBaseClient<number | null, algosdk.Address |
156156
* Prepares transactions to update the ordering app using the latest contracts.
157157
* @returns A promise that resolves the transaction array.
158158
*/
159-
// TODO: Once the contracts are public, use getCompiledPrograms for approval and clear programs
160159
async prepareUpdateOrderingAppTransactions(): Promise<Transaction[]> {
161160
if (!this.appId) {
162161
throw new Error("Application ID not provided");

src/order/utils.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ function createPaddedByteArray(
1313
return joinByteArrays(...array.map((num) => intToBytes(num, byteSize)));
1414
}
1515

16-
async function computeSHA512(fileArrayBuffer: Uint8Array) {
17-
const hashBuffer = await crypto.subtle.digest("SHA-512", fileArrayBuffer);
18-
const hashArray = Array.from(new Uint8Array(hashBuffer));
19-
20-
// Extract the first 32 bytes (256 bits)
21-
const sha512_256HashArray = hashArray.slice(0, 32);
22-
23-
// Convert the byte array to a hexadecimal string
24-
const hashHex = Array.from(sha512_256HashArray)
25-
.map((byte) => byte.toString(16).padStart(2, "0"))
26-
.join("");
27-
28-
return hashHex;
29-
}
30-
3116
// Fetch and compile the approval and clear programs
3217
async function getCompiledPrograms() {
3318
const approvalSourceResponse = await fetch(
@@ -46,4 +31,4 @@ async function getCompiledPrograms() {
4631
return {approvalProgram, clearProgram};
4732
}
4833

49-
export {computeSHA512, createPaddedByteArray, getCompiledPrograms, joinByteArrays};
34+
export {createPaddedByteArray, getCompiledPrograms};

0 commit comments

Comments
 (0)