Skip to content

Commit

Permalink
Upgrade to SDK 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
h0ngcha0 committed Aug 25, 2024
1 parent 1e5b2b5 commit 0db6b4c
Show file tree
Hide file tree
Showing 7 changed files with 616 additions and 523 deletions.
16 changes: 7 additions & 9 deletions .project.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
{
"fullNodeVersion": "v2.12.0",
"fullNodeVersion": "v3.5.0",
"compilerOptionsUsed": {
"ignoreUnusedConstantsWarnings": false,
"ignoreUnusedVariablesWarnings": false,
"ignoreUnusedFieldsWarnings": false,
"ignoreUnusedPrivateFunctionsWarnings": false,
"ignoreUpdateFieldsCheckWarnings": false,
"ignoreCheckExternalCallerWarnings": false
"ignoreCheckExternalCallerWarnings": false,
"ignoreUnusedFunctionReturnWarnings": false
},
"infos": {
"IFungibleToken": {
"sourceFile": "../node_modules/@alephium/web3/std/fungible_token_interface.ral",
"sourceCodeHash": "6809cb06fb20fa7edf529461998beeebd12b1636d439612cca2f84214dbf4a20",
"sourceCodeHash": "62910bf11e1eeb6cb2fd468626ff606a9b06306b2b81590c3b10f6deb5966bde",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
"codeHashDebug": ""
},
"TokenFaucet": {
"sourceFile": "token.ral",
"sourceCodeHash": "3a12c7604f3899bde03ab81e81eac394a53e723c6e99bc38aeb722689826759f",
"bytecodeDebugPatch": "=20-2+67=101+3a0007e02=1+75468652063757272656e742062616c616e63652069732000=46",
"codeHashDebug": "a3309aa3a0dbd0c53b67a0c422316dcbc0571d8fa5f9ea2ab374b5c110f4efe2",
"warnings": []
"codeHashDebug": "a3309aa3a0dbd0c53b67a0c422316dcbc0571d8fa5f9ea2ab374b5c110f4efe2"
},
"Withdraw": {
"sourceFile": "withdraw.ral",
"sourceCodeHash": "52423580f02f5aab7050bfb9a14b497ea4bdcb10b3444483650f3dad8e0e5330",
"bytecodeDebugPatch": "",
"codeHashDebug": "",
"warnings": []
"codeHashDebug": ""
}
}
}
125 changes: 109 additions & 16 deletions artifacts/ts/TokenFaucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import {
getContractEventsCurrentCount,
TestContractParamsWithoutMaps,
TestContractResultWithoutMaps,
SignExecuteContractMethodParams,
SignExecuteScriptTxResult,
signExecuteMethod,
addStdIdToFields,
encodeContractFields,
} from "@alephium/web3";
import { default as TokenFaucetContractJson } from "../TokenFaucet.ral.json";
import { getContractByCodeHash } from "./contracts";
Expand Down Expand Up @@ -64,6 +69,10 @@ export namespace TokenFaucetTypes {
params: Omit<CallContractParams<{}>, "args">;
result: CallContractResult<bigint>;
};
withdraw: {
params: CallContractParams<{ amount: bigint }>;
result: CallContractResult<null>;
};
}
export type CallMethodParams<T extends keyof CallMethodTable> =
CallMethodTable[T]["params"];
Expand All @@ -77,18 +86,57 @@ export namespace TokenFaucetTypes {
? CallMethodTable[MaybeName]["result"]
: undefined;
};
export type MulticallReturnType<Callss extends MultiCallParams[]> =
Callss["length"] extends 1
? MultiCallResults<Callss[0]>
: { [index in keyof Callss]: MultiCallResults<Callss[index]> };

export interface SignExecuteMethodTable {
getSymbol: {
params: Omit<SignExecuteContractMethodParams<{}>, "args">;
result: SignExecuteScriptTxResult;
};
getName: {
params: Omit<SignExecuteContractMethodParams<{}>, "args">;
result: SignExecuteScriptTxResult;
};
getDecimals: {
params: Omit<SignExecuteContractMethodParams<{}>, "args">;
result: SignExecuteScriptTxResult;
};
getTotalSupply: {
params: Omit<SignExecuteContractMethodParams<{}>, "args">;
result: SignExecuteScriptTxResult;
};
balance: {
params: Omit<SignExecuteContractMethodParams<{}>, "args">;
result: SignExecuteScriptTxResult;
};
withdraw: {
params: SignExecuteContractMethodParams<{ amount: bigint }>;
result: SignExecuteScriptTxResult;
};
}
export type SignExecuteMethodParams<T extends keyof SignExecuteMethodTable> =
SignExecuteMethodTable[T]["params"];
export type SignExecuteMethodResult<T extends keyof SignExecuteMethodTable> =
SignExecuteMethodTable[T]["result"];
}

class Factory extends ContractFactory<
TokenFaucetInstance,
TokenFaucetTypes.Fields
> {
getInitialFieldsWithDefaultValues() {
return this.contract.getInitialFieldsWithDefaultValues() as TokenFaucetTypes.Fields;
encodeFields(fields: TokenFaucetTypes.Fields) {
return encodeContractFields(
addStdIdToFields(this.contract, fields),
this.contract.fieldsSig,
[]
);
}

eventIndex = { Withdraw: 0 };
consts = { ErrorCodes: { InvalidWithdrawAmount: BigInt(0) } };
consts = { ErrorCodes: { InvalidWithdrawAmount: BigInt("0") } };

at(address: string): TokenFaucetInstance {
return new TokenFaucetInstance(address);
Expand All @@ -101,47 +149,47 @@ class Factory extends ContractFactory<
"testArgs"
>
): Promise<TestContractResultWithoutMaps<HexString>> => {
return testMethod(this, "getSymbol", params);
return testMethod(this, "getSymbol", params, getContractByCodeHash);
},
getName: async (
params: Omit<
TestContractParamsWithoutMaps<TokenFaucetTypes.Fields, never>,
"testArgs"
>
): Promise<TestContractResultWithoutMaps<HexString>> => {
return testMethod(this, "getName", params);
return testMethod(this, "getName", params, getContractByCodeHash);
},
getDecimals: async (
params: Omit<
TestContractParamsWithoutMaps<TokenFaucetTypes.Fields, never>,
"testArgs"
>
): Promise<TestContractResultWithoutMaps<bigint>> => {
return testMethod(this, "getDecimals", params);
return testMethod(this, "getDecimals", params, getContractByCodeHash);
},
getTotalSupply: async (
params: Omit<
TestContractParamsWithoutMaps<TokenFaucetTypes.Fields, never>,
"testArgs"
>
): Promise<TestContractResultWithoutMaps<bigint>> => {
return testMethod(this, "getTotalSupply", params);
return testMethod(this, "getTotalSupply", params, getContractByCodeHash);
},
balance: async (
params: Omit<
TestContractParamsWithoutMaps<TokenFaucetTypes.Fields, never>,
"testArgs"
>
): Promise<TestContractResultWithoutMaps<bigint>> => {
return testMethod(this, "balance", params);
return testMethod(this, "balance", params, getContractByCodeHash);
},
withdraw: async (
params: TestContractParamsWithoutMaps<
TokenFaucetTypes.Fields,
{ amount: bigint }
>
): Promise<TestContractResultWithoutMaps<null>> => {
return testMethod(this, "withdraw", params);
return testMethod(this, "withdraw", params, getContractByCodeHash);
},
};
}
Expand All @@ -151,7 +199,8 @@ export const TokenFaucet = new Factory(
Contract.fromJson(
TokenFaucetContractJson,
"=20-2+67=101+3a0007e02=1+75468652063757272656e742062616c616e63652069732000=46",
"a3309aa3a0dbd0c53b67a0c422316dcbc0571d8fa5f9ea2ab374b5c110f4efe2"
"a3309aa3a0dbd0c53b67a0c422316dcbc0571d8fa5f9ea2ab374b5c110f4efe2",
[]
)
);

Expand Down Expand Up @@ -182,7 +231,7 @@ export class TokenFaucetInstance extends ContractInstance {
);
}

methods = {
view = {
getSymbol: async (
params?: TokenFaucetTypes.CallMethodParams<"getSymbol">
): Promise<TokenFaucetTypes.CallMethodResult<"getSymbol">> => {
Expand Down Expand Up @@ -238,16 +287,60 @@ export class TokenFaucetInstance extends ContractInstance {
getContractByCodeHash
);
},
withdraw: async (
params: TokenFaucetTypes.CallMethodParams<"withdraw">
): Promise<TokenFaucetTypes.CallMethodResult<"withdraw">> => {
return callMethod(
TokenFaucet,
this,
"withdraw",
params,
getContractByCodeHash
);
},
};

transact = {
getSymbol: async (
params: TokenFaucetTypes.SignExecuteMethodParams<"getSymbol">
): Promise<TokenFaucetTypes.SignExecuteMethodResult<"getSymbol">> => {
return signExecuteMethod(TokenFaucet, this, "getSymbol", params);
},
getName: async (
params: TokenFaucetTypes.SignExecuteMethodParams<"getName">
): Promise<TokenFaucetTypes.SignExecuteMethodResult<"getName">> => {
return signExecuteMethod(TokenFaucet, this, "getName", params);
},
getDecimals: async (
params: TokenFaucetTypes.SignExecuteMethodParams<"getDecimals">
): Promise<TokenFaucetTypes.SignExecuteMethodResult<"getDecimals">> => {
return signExecuteMethod(TokenFaucet, this, "getDecimals", params);
},
getTotalSupply: async (
params: TokenFaucetTypes.SignExecuteMethodParams<"getTotalSupply">
): Promise<TokenFaucetTypes.SignExecuteMethodResult<"getTotalSupply">> => {
return signExecuteMethod(TokenFaucet, this, "getTotalSupply", params);
},
balance: async (
params: TokenFaucetTypes.SignExecuteMethodParams<"balance">
): Promise<TokenFaucetTypes.SignExecuteMethodResult<"balance">> => {
return signExecuteMethod(TokenFaucet, this, "balance", params);
},
withdraw: async (
params: TokenFaucetTypes.SignExecuteMethodParams<"withdraw">
): Promise<TokenFaucetTypes.SignExecuteMethodResult<"withdraw">> => {
return signExecuteMethod(TokenFaucet, this, "withdraw", params);
},
};

async multicall<Calls extends TokenFaucetTypes.MultiCallParams>(
calls: Calls
): Promise<TokenFaucetTypes.MultiCallResults<Calls>> {
async multicall<Callss extends TokenFaucetTypes.MultiCallParams[]>(
...callss: Callss
): Promise<TokenFaucetTypes.MulticallReturnType<Callss>> {
return (await multicallMethods(
TokenFaucet,
this,
calls,
callss,
getContractByCodeHash
)) as TokenFaucetTypes.MultiCallResults<Calls>;
)) as TokenFaucetTypes.MulticallReturnType<Callss>;
}
}
3 changes: 2 additions & 1 deletion artifacts/ts/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
SignerProvider,
HexString,
} from "@alephium/web3";
import { getContractByCodeHash } from "./contracts";
import { default as WithdrawScriptJson } from "../Withdraw.ral.json";

export const Withdraw = new ExecutableScript<{
token: HexString;
amount: bigint;
}>(Script.fromJson(WithdrawScriptJson, ""));
}>(Script.fromJson(WithdrawScriptJson, "", []), getContractByCodeHash);
Loading

0 comments on commit 0db6b4c

Please sign in to comment.