-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
259 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
Before - After | ||
247612476655386 - 275243041767645 | ||
300000000000000 | ||
|
||
21610828908456 | ||
|
||
25000000000000 | ||
|
||
|
||
243042850032853 | ||
221875559042014 | ||
|
||
|
||
membership proposals | ||
247614509999979 - 266039310333543 | ||
|
||
358970226156 - 118590061078576 | ||
|
||
187614509999979 - 206039310333543 | ||
|
||
Sponsor Proposal - 130656126878523 | ||
|
||
|
||
Funding Proposal (vitalpointai.testnet) | ||
188630371650791 - 207681119831705 | ||
|
||
194825900764149 - 215246477127078 (guildleder funding proposal) | ||
|
||
guildleader.testnet submits member proposal: 206038691588424 | ||
vitalpointai.testnet sponsors: 218105285640275 | ||
vitalpointai.testnet votes: 29352828178908 | ||
vitalpointai.testnet process: 31724744405292 | ||
|
||
caller - function - used gas at start - used gas at end | ||
guildleader.testnet - submitProposal - 358952633172 - 206090001065511 | ||
vitalpointai.testnet - sponsorProposal - 273877186542 - 218156124711023 | ||
vitalpointai.testnet - submitVote - 202967778444 - 29401572885588 | ||
vitalpointai.testnet - processProposal - 179369373783 - 31775583476040 | ||
guildleader.testnet - submitProposal - 358952633172 - fails - exceeds prepaid gas (separately - costs: 215246477127078) | ||
|
||
transfer_from (vpc contract) | ||
235203514527 - 21846032422983 = 21610828908456 | ||
|
||
inc_allowance (dao) | ||
150751616526 - 17178419405754 = 17027667789228 | ||
|
||
transfer_from (dao) | ||
185771684913 - 26400123400347 = 26 214 351 715 434 | ||
|
||
300000000000000 | ||
guildleader.testnet - submitProposal (member) - 19965643342536 19965808072536 19965801786786 19961672676720 20074904868867 20074887962367 | ||
vitalpointai.testnet- sponsorProposal - 27651953053530 27652117783530 27652111497780 27650631103260 27407022301542 26250882567363 | ||
vitalpointai.testnet- processProposal - 118315710494739 114674314386474 113111261503134 113109781108614 114771892934922 113601429557952 | ||
guildleader.testnet - submitProposal (member) 102075318988827 102071492654748 103507037776407 103507020869907 | ||
vitalpointai.testnet- sponsorProposal 196973843746485 196972363351965 >200 dies dies | ||
vitalpointai.testnet- processProposal died | ||
|
||
guildleader.testnet - submitProposal (member proposal ) - 20074887962367 | ||
vitalpointai.testnet- sponsorProposal - 26250882567363 | ||
vitalpointai.testnet- processProposal - 113601429557952 | ||
guildleader.testnet - submitProposal (member proposal) 103507020869907 | ||
vitalpointai.testnet- sponsorProposal dies | ||
vitalpointai.testnet- processProposal | ||
|
||
storage | ||
96495 96943 97247 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
export function tokenName(token: AccountId): ContractPromise { //token is the fungible token contract account for the token being asked balance for given account | ||
let args = new TokenNameArgs() | ||
|
||
let promise = ContractPromise.create( | ||
token, // contract account Id | ||
"getTokenName", // method | ||
args.encode(), // serialized contract method arguments as Uint8Array | ||
DEFAULT_GAS_VALUE, // gas attached to call | ||
u128.Zero) // attached deposit to be sent with call | ||
|
||
//setting up args for the callback | ||
let responseArgs = new OnGetTokenNameCalled() | ||
logging.log(responseArgs) | ||
|
||
logging.log(Context.contractName) | ||
|
||
let callbackPromise = promise.then( | ||
Context.contractName, | ||
"_tokenName", | ||
responseArgs.encode(), | ||
2 | ||
) | ||
return callbackPromise | ||
} | ||
|
||
export function _thistokenName(): string { | ||
const name = '' | ||
let results = ContractPromise.getResults() | ||
|
||
assert(results.length > 0, "should be contract promise result") | ||
let data = results[0] | ||
|
||
//verifying the remote contract call succeeded | ||
if(data.status == 1) { | ||
//Decoding data from the bytes buffer into the local object | ||
logging.log('data buffer' + data.buffer.toString() + 'data status' + data.status.toString()) | ||
let result = decode<OnGetTokenCalled>(data.buffer) | ||
logging.log(result) | ||
return result.tokenName.tokenName | ||
} | ||
return name | ||
} | ||
|
||
@nearBindgen | ||
class OnGetTokenCalled { | ||
constructor(public tokenName: OnGetTokenNameCalled){} | ||
} | ||
|
||
|
||
|
||
|
||
getATokenName(token: AccountId): void { | ||
|
||
logging.log("prepaid gas " + Context.prepaidGas.toString()) | ||
let promise = ContractPromise.create( | ||
token, // contract account Id (vpc.vitalpointai.testnet) | ||
"getTokenName", // method | ||
new Uint8Array(0), // serialized contract method arguments as Uint8Array - method needs no args | ||
u64(300000000000000), // gas attached to call | ||
u128.Zero) // attached deposit to be sent with call | ||
|
||
//setting up args for the callback | ||
// let responseArgs: OnGetTokenNameCalled = { | ||
// tokenName: '' | ||
// } | ||
let responseArgs = new OnGetTokenNameCalled() | ||
let callbackPromise = promise.then( | ||
Context.contractName, | ||
"_tokenName", | ||
responseArgs.encode(), | ||
2 | ||
) | ||
callbackPromise.returnAsResult() | ||
} | ||
|
||
_tokenName(): string { | ||
let results = ContractPromise.getResults() | ||
assert(results.length > 0, "should be contract promise result") | ||
let data = results[0] | ||
|
||
//verifying the remote contract call succeeded | ||
if(data.status == 1) { | ||
//Decoding data from the bytes buffer into the local object | ||
let result = decode<OnGetTokenNameCalled>(data.buffer) | ||
logging.log(result) | ||
return result.tokenName | ||
} | ||
return '' | ||
} | ||
|
||
export class fungibleTokenApi { | ||
transferFrom(from: AccountId, to: AccountId, amount: Amount, tributeToken: AccountId): ContractPromise { //tributeToken is the fungible token contract account for the tributeToken | ||
let args: TransferFromArgs = { owner_id: from, new_owner_id: to, amount: amount } | ||
let promise = ContractPromise.create(tributeToken, "transfer_from", args.encode(), 100000000000000, u128.Zero) | ||
|
||
return promise | ||
} | ||
|
||
_transferFrom(): bool { | ||
let results = ContractPromise.getResults() | ||
assert(results.length > 0, "should be contract promise result") | ||
let result = results[0] | ||
|
||
//verifying remote contract call succeeded | ||
if(result.status == 1) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
transfer(to: AccountId, amount: Amount, token: AccountId): ContractPromise { //token is the fungible token contract account for the token being transferred | ||
let args: TransferArgs = { to, amount } | ||
let promise = ContractPromise.create(token, "transfer", args.encode(), DEFAULT_GAS_VALUE, u128.Zero) | ||
|
||
return promise | ||
} | ||
|
||
_transfer(): bool { | ||
let results = ContractPromise.getResults() | ||
assert(results.length > 0, "should be contract promise result") | ||
let result = results[0] | ||
|
||
//verifying remote contract call succeeded | ||
if(result.status ==1) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
balanceOf(token: AccountId, account: AccountId): ContractPromise { //token is the fungible token contract account for the token being asked balance for given account | ||
let args: BalanceArgs = {account} | ||
|
||
let promise = ContractPromise.create( | ||
token, // contract account Id | ||
"get_balance", // method | ||
args.encode(), // serialized contract method arguments as Uint8Array | ||
DEFAULT_GAS_VALUE, // gas attached to call | ||
u128.Zero) // attached deposit to be sent with call | ||
|
||
//setting up args for the callback | ||
let responseArgs = new OnBalanceCalledArgs() | ||
|
||
|
||
let callbackPromise = promise.then( | ||
Context.contractName, | ||
"_balanceOf", | ||
responseArgs.encode(), | ||
2 | ||
) | ||
return callbackPromise | ||
} | ||
|
||
_balanceOf(account: AccountId): u128 { | ||
const amount = u128.Zero | ||
let results = ContractPromise.getResults() | ||
assert(results.length > 0, "should be contract promise result") | ||
let data = results[0] | ||
|
||
//verifying the remote contract call succeeded | ||
if(data.status == 1) { | ||
//Decoding data from the bytes buffer into the local object | ||
let balance = decode<OnBalanceCalledArgs>(data.buffer) | ||
logging.log(balance) | ||
return balance.amount | ||
} | ||
return amount | ||
} | ||
} | ||
|
||
export function submitMemberProposal(applicant: AccountId, shares: u128, tribute: u128, tributeType: string, proposalIdentifier: string): u64 { | ||
REENTRANTGUARD.nonReentrantOpen() | ||
assert(env.isValidAccountID(applicant), ERR_INVALID_ACCOUNT_ID) | ||
assert(members.get(applicant)==null, ERR_ALREADY_MEMBER) | ||
assert(shares > u128.Zero, ERR_MUSTBE_GREATERTHAN_ZERO) | ||
assert(tribute > u128.Zero, ERR_MUSTBE_GREATERTHAN_ZERO) | ||
|
||
// collect tribute from proposer and store it in the Moloch until the proposal is processed | ||
let ftAPI = new tokenAPI() | ||
ftAPI.incAllowance(tribute, tributeType) | ||
ftAPI.transferFrom(Context.sender, MOLOCH_CONTRACT_ACCOUNT, tribute, tributeType) | ||
|
||
_unsafeAddToBalance(ESCROW, tributeType, tribute) | ||
logging.log('user member token balance '+ getUserTokenBalance(ESCROW, tributeType).toString()) | ||
|
||
let flags = new Array<bool>(7) // [sponsored, processed, didPass, cancelled, whitelist, guildkick, member] | ||
flags[6] = true; // member Proposal | ||
|
||
_submitProposal(proposalIdentifier, applicant, shares, u128.Zero, tribute, tributeType, u128.Zero, '', flags) | ||
REENTRANTGUARD.nonReentrantClose() | ||
return proposalCount-1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters